:root {
  --bg: #0b1017;
  --bg-2: #10171f;
  --surface: #151d27;
  --surface-2: #1b2531;
  --border: #253242;
  --border-2: #2f3f52;
  --text: #e7ecf3;
  --muted: #8c9bb0;
  --navy: #12355b;
  --blue: #3b82f6;
  --blue-2: #2563eb;
  --red: #c1272d;
  --red-2: #a31f25;
  --gold: #d9b85e;
  --green: #22c55e;
  --amber: #f59e0b;
  --radius: 12px;
  --sidebar: 250px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, rgba(59,130,246,.12), transparent 60%),
              radial-gradient(900px 500px at -10% 100%, rgba(193,39,45,.10), transparent 60%),
              var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
body.app { display: flex; }
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: linear-gradient(180deg, #0f1620 0%, #0b1017 100%);
  border-right: 1px solid var(--border);
  min-height: 100vh;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: .75rem;
  padding: 1.1rem 1.1rem .9rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.brand:hover { text-decoration: none; }
.brand img { width: 46px; height: auto; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); }
.brand strong { display: block; font-size: 1.05rem; letter-spacing: .02em; }
.brand small { display: block; color: var(--gold); font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; }
.sidebar nav { padding: .75rem .6rem; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .8rem; border-radius: 9px;
  color: var(--muted); font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: linear-gradient(90deg, rgba(59,130,246,.22), rgba(59,130,246,.06)); color: #fff; box-shadow: inset 3px 0 0 var(--blue); }
.sidebar-user {
  display: flex; align-items: center; gap: .6rem;
  padding: .9rem 1rem; border-top: 1px solid var(--border);
}
.sidebar-user .who { flex: 1; min-width: 0; }
.sidebar-user .who strong { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who small { color: var(--muted); font-size: .75rem; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
  background: linear-gradient(135deg, var(--red), var(--navy));
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: #fff;
}
.icon-btn { color: var(--muted); padding: .35rem; border-radius: 8px; display: inline-flex; }
.icon-btn:hover { background: var(--surface); color: var(--text); }
.nav-toggle { display: none; }
.backdrop { display: none; }

.content { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; max-width: 1400px; }
body.bare .content { max-width: none; padding: 0; display: grid; place-items: center; min-height: 100vh; }

.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head .sub { color: var(--muted); margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.grid { display: grid; gap: 1.25rem; align-items: start; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: 2fr 1fr; }

.stat { padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: .2rem; position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.stat .value { font-size: 2rem; font-weight: 700; letter-spacing: -.01em; }
.stat .hint { color: var(--muted); font-size: .8rem; }
.stat::after { content: ""; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px; border-radius: 50%; opacity: .15; }
.stat.new::after { background: var(--blue); }
.stat.pending::after { background: var(--amber); }
.stat.sold::after { background: var(--green); }
.stat.money::after { background: var(--gold); }
.stat a { color: inherit; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: .15rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  border: 1px solid transparent; white-space: nowrap;
}
.status-new     { background: rgba(59,130,246,.15); color: #93c5fd; border-color: rgba(59,130,246,.35); }
.status-pending { background: rgba(245,158,11,.15); color: #fcd34d; border-color: rgba(245,158,11,.35); }
.status-sold    { background: rgba(34,197,94,.15);  color: #86efac; border-color: rgba(34,197,94,.35); }
.exp-submitted  { background: rgba(140,155,176,.15); color: #cbd5e1; border-color: rgba(140,155,176,.35); }
.exp-approved   { background: rgba(34,197,94,.15);  color: #86efac; border-color: rgba(34,197,94,.35); }
.exp-rejected   { background: rgba(193,39,45,.18);  color: #fca5a5; border-color: rgba(193,39,45,.4); }
.badge.role-superuser { background: rgba(217,184,94,.15); color: var(--gold); border-color: rgba(217,184,94,.4); }
.badge.role-admin { background: rgba(193,39,45,.18); color: #fca5a5; border-color: rgba(193,39,45,.4); }
.badge.role-agent { background: rgba(59,130,246,.15); color: #93c5fd; border-color: rgba(59,130,246,.35); }
.badge.off { background: rgba(193,39,45,.18); color: #fca5a5; border-color: rgba(193,39,45,.4); }
.badge.cat { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 9px; border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; line-height: 1.2; text-decoration: none; transition: .15s;
}
.btn:hover { background: #22303f; border-color: #3b4d63; text-decoration: none; }
.btn.primary { background: var(--blue-2); border-color: var(--blue-2); color: #fff; }
.btn.primary:hover { background: var(--blue); border-color: var(--blue); }
.btn.danger { background: transparent; border-color: rgba(193,39,45,.5); color: #fca5a5; }
.btn.danger:hover { background: rgba(193,39,45,.2); }
.btn.success { background: rgba(34,197,94,.15); border-color: rgba(34,197,94,.4); color: #86efac; }
.btn.success:hover { background: rgba(34,197,94,.3); }
.btn.gold { background: linear-gradient(135deg, #d9b85e, #b8933d); border-color: #b8933d; color: #1b1608; }
.btn.sm { padding: .3rem .65rem; font-size: .8rem; border-radius: 7px; }
.btn.block { width: 100%; justify-content: center; }
.btn svg { flex: none; }

/* ---------- Forms ---------- */
form { margin: 0; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; text-transform: uppercase; letter-spacing: .05em; }
.field { margin-bottom: 1rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
input[type=date], input[type=datetime-local], input[type=time], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .6rem .75rem; border-radius: 9px;
  border: 1px solid var(--border-2); background: var(--bg-2); color: var(--text);
  font: inherit; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
input[type=file] { padding: .45rem .6rem; }
input[type=file]::file-selector-button {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2);
  padding: .35rem .7rem; border-radius: 7px; margin-right: .75rem; font: inherit; cursor: pointer;
}
textarea { min-height: 110px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%238c9bb0' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin-top: .5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.form-actions .spacer { flex: 1; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .95rem; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }
.inline-form { display: inline; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 160px; }
.filters .field.grow { flex: 1; min-width: 220px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .7rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: var(--bg-2); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: rgba(255,255,255,.025); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.row-link { color: var(--text); font-weight: 600; }

/* ---------- Tabs / pills ---------- */
.pills { display: flex; gap: .4rem; flex-wrap: wrap; }
.pills a { padding: .4rem .85rem; border-radius: 999px; border: 1px solid var(--border-2); color: var(--muted); font-size: .85rem; font-weight: 600; }
.pills a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.pills a.active { background: var(--blue-2); border-color: var(--blue-2); color: #fff; }
.pills a .n { opacity: .7; margin-left: .3rem; }

/* ---------- Flash ---------- */
.flash { padding: .75rem 1rem; border-radius: 9px; margin-bottom: 1rem; border: 1px solid; font-weight: 500; }
.flash.success { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.4); color: #bbf7d0; }
.flash.error { background: rgba(193,39,45,.15); border-color: rgba(193,39,45,.5); color: #fecaca; }
.flash.info { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.4); color: #bfdbfe; }

/* ---------- Login ---------- */
.login-box { width: 100%; max-width: 420px; padding: 2rem; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); margin: 1rem; }
.login-box .logo { text-align: center; margin-bottom: 1.25rem; }
.login-box .logo img { width: 120px; height: auto; filter: drop-shadow(0 6px 16px rgba(0,0,0,.6)); }
.login-box h1 { text-align: center; font-size: 1.35rem; }
.login-box .tag { text-align: center; color: var(--gold); text-transform: uppercase; letter-spacing: .15em; font-size: .72rem; margin-bottom: 1.5rem; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cal-head h1 { margin: 0; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal .dow { background: var(--bg-2); color: var(--muted); padding: .5rem; text-align: center; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.cal .day { background: var(--surface); min-height: 118px; padding: .4rem .45rem; position: relative; display: flex; flex-direction: column; gap: 3px; }
.cal .day.other { background: var(--bg-2); opacity: .55; }
.cal .day.today { background: rgba(59,130,246,.08); }
.cal .day .n { font-size: .8rem; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.cal .day.today .n { color: var(--blue); }
.cal .day .n a.add { opacity: 0; color: var(--muted); font-size: 1rem; line-height: 1; }
.cal .day:hover .n a.add { opacity: 1; }
.evt { display: block; padding: .2rem .4rem; border-radius: 5px; font-size: .75rem; line-height: 1.25; color: #fff;
  background: rgba(59,130,246,.35); border-left: 3px solid var(--blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.evt:hover { background: rgba(59,130,246,.55); text-decoration: none; }
.evt.mine { background: rgba(217,184,94,.28); border-left-color: var(--gold); }
.evt.mine:hover { background: rgba(217,184,94,.45); }
.evt.past { opacity: .55; }
.evt b { font-weight: 600; margin-right: .25rem; }
.more { font-size: .72rem; color: var(--muted); }

.agenda { list-style: none; margin: 0; padding: 0; }
.agenda li { display: flex; gap: .9rem; padding: .7rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.agenda li:last-child { border-bottom: 0; }
.agenda .when { flex: 0 0 82px; text-align: center; background: var(--bg-2); border: 1px solid var(--border); border-radius: 9px; padding: .35rem .2rem; }
.agenda .when b { display: block; font-size: 1.15rem; line-height: 1.1; }
.agenda .when span { font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.agenda .what { flex: 1; min-width: 0; }
.agenda .what strong { display: block; }
.agenda .what small { color: var(--muted); display: block; }

/* ---------- Misc ---------- */
.notes-list { list-style: none; padding: 0; margin: 0; }
.notes-list li { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.notes-list li:last-child { border-bottom: 0; }
.notes-list .meta { font-size: .78rem; color: var(--muted); margin-bottom: .2rem; }
.notes-list .body { white-space: pre-wrap; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: .35rem 1rem; font-size: .95rem; }
.dl dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; padding-top: .15rem; }
.dl dd { margin: 0; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border-2); background: var(--bg-2); display: block; }
.thumb-lg { max-width: 100%; max-height: 70vh; border-radius: 10px; border: 1px solid var(--border-2); }
.status-switch { display: flex; gap: .4rem; flex-wrap: wrap; }
.status-switch button { border: 1px solid var(--border-2); background: var(--bg-2); color: var(--muted); padding: .4rem .8rem; border-radius: 999px; font: inherit; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; cursor: pointer; }
.status-switch button.on-new { background: rgba(59,130,246,.2); color: #93c5fd; border-color: rgba(59,130,246,.5); }
.status-switch button.on-pending { background: rgba(245,158,11,.2); color: #fcd34d; border-color: rgba(245,158,11,.5); }
.status-switch button.on-sold { background: rgba(34,197,94,.2); color: #86efac; border-color: rgba(34,197,94,.5); }
.status-switch button:hover { color: var(--text); }
.kv { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.kv div small { display: block; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.kv div b { font-size: 1.1rem; }
.bar { height: 8px; background: var(--bg-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--gold)); }
.setup-steps { list-style: none; padding: 0; margin: 0 0 1rem; color: var(--muted); font-size: .9rem; }
.setup-steps li { padding: .25rem 0; }
.setup-steps li::before { content: "✓ "; color: var(--green); }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .nav-toggle { display: grid; place-items: center; position: fixed; top: .7rem; left: .7rem; z-index: 40; width: 42px; height: 42px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border-2); color: var(--text); cursor: pointer; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 15; }
  .content { padding: 4.2rem 1rem 3rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .cal .day { min-height: 70px; }
  .evt { font-size: .65rem; }
  .dl { grid-template-columns: 1fr; }
}
