/* ============================================================
   LRD Abonamente — design system
   ============================================================ */
:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --border:    #e5e9f2;
  --text:      #1a2233;
  --text-soft: #5b6577;
  --text-mute: #8a94a6;
  --primary:   #2f5fe0;
  --primary-d: #2449b8;
  --primary-soft:#eaf0ff;
  --ok:        #12925b;
  --ok-soft:   #e2f6ec;
  --warn:      #b7791f;
  --warn-soft: #fdf3e0;
  --err:       #d1373b;
  --err-soft:  #fdeaea;
  --muted:     #64748b;
  --muted-soft:#eef1f6;
  --shadow:    0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --shadow-lg: 0 8px 32px rgba(16,24,40,.14);
  --radius:    12px;
  --radius-sm: 8px;
  --sidebar-w: 244px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0e131c; --surface:#171e2a; --surface-2:#1d2634; --border:#2a3444;
    --text:#e6ebf3; --text-soft:#a7b2c4; --text-mute:#78859a;
    --primary:#6a92ff; --primary-d:#5680f2; --primary-soft:#1c2a49;
    --ok:#37c98a; --ok-soft:#12301f; --warn:#e0a942; --warn-soft:#332612;
    --err:#f0686c; --err-soft:#331a1b; --muted:#94a3b8; --muted-soft:#232d3d;
    --shadow:0 1px 2px rgba(0,0,0,.3),0 4px 16px rgba(0,0,0,.3);
    --shadow-lg:0 8px 32px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .4em; font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
small { color: var(--text-mute); }

/* ---------- Layout shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
  transition: transform .22s ease;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 20px;
  font-weight: 750; font-size: 1.05rem; border-bottom: 1px solid var(--border);
}
.sidebar__brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-d)); color: #fff; font-weight: 800;
}
.nav { padding: 12px 12px; overflow-y: auto; flex: 1; }
.nav__section { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-mute); padding: 14px 12px 6px; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 550; margin-bottom: 2px; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a .ic { width: 19px; height: 19px; flex-shrink: 0; }
.nav a .badge { margin-left: auto; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 20px; position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-weight: 650; font-size: 1.05rem; }
.topbar__spacer { flex: 1; }
.burger { display: none; background: none; border: 0; cursor: pointer; padding: 6px; color: var(--text); }
.content { padding: 26px 30px; width: 100%; max-width: none; }
@media (min-width: 1500px) { .content { padding: 30px 40px; } }
@media (min-width: 1920px) { .content { padding: 34px 56px; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none; transition: all .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-d); }
.btn--danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn--danger:hover { filter: brightness(.94); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--sm { padding: 6px 11px; font-size: .82rem; }
.btn--icon { padding: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card { transition: box-shadow .16s ease; }
.card__head { padding: 17px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card__head h2, .card__head h3 { margin: 0; font-size: 1.02rem; display: flex; align-items: center; gap: 9px; }
.card__head h3 .ic, .card__head h2 .ic { color: var(--text-mute); }
.card__body { padding: 22px; }
.card__body--flush { padding: 0; }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px,1fr)); gap: 18px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .14s ease, box-shadow .14s ease; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat__label { color: var(--text-mute); font-size: .8rem; font-weight: 650; display: flex; align-items: center; gap: 9px; text-transform: uppercase; letter-spacing: .03em; }
.stat__value { font-size: 2rem; font-weight: 780; margin-top: 12px; letter-spacing: -.02em; line-height: 1.1; }
.stat__sub { font-size: .8rem; color: var(--text-soft); margin-top: 4px; }
.stat__ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.stat:nth-child(1) .stat__ic { background: var(--primary-soft); color: var(--primary); }
.stat:nth-child(2) .stat__ic { background: var(--ok-soft); color: var(--ok); }
.stat:nth-child(3) .stat__ic { background: var(--warn-soft); color: var(--warn); }
.stat:nth-child(4) .stat__ic { background: #efe7fb; color: #7c3aed; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stat:nth-child(4) .stat__ic { background: #241a3d; color: #a78bfa; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; padding: 12px 18px; color: var(--text-mute); font-weight: 700;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border);
  white-space: nowrap; background: var(--surface-2); }
.tbl td { padding: 14px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl a.rowlink { font-weight: 600; color: var(--text); }
.tbl a.rowlink:hover { color: var(--primary); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 650; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--err { background: var(--err-soft); color: var(--err); }
.badge--muted { background: var(--muted-soft); color: var(--muted); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px 22px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .span2 { grid-column: span 2; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: auto; } }
.field label { display: block; font-weight: 600; font-size: .84rem; margin-bottom: 6px; color: var(--text-soft); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: .92rem; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; min-height: 78px; }
.field .hint { font-size: .78rem; color: var(--text-mute); margin-top: 4px; }
.field--check { display: flex; align-items: center; gap: 9px; }
.field--check input { width: auto; }
.field--check label { margin: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }

/* ---------- Flash / alerts ---------- */
.flashes { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  font-weight: 550; display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); }
.alert--success { border-left: 3px solid var(--ok); }
.alert--error { border-left: 3px solid var(--err); }
.alert--warning { border-left: 3px solid var(--warn); }
.alert--info { border-left: 3px solid var(--primary); }
.alert__close { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--text-mute); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.page-head .spacer { flex: 1; }
.breadcrumb { font-size: .84rem; color: var(--text-mute); margin-bottom: 4px; }
.breadcrumb a { color: var(--text-soft); }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-mute); }
.empty .ic { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--text-mute); opacity: .6; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 460px; position: relative; display: flex; }
.toolbar .search input { padding-left: 38px; width: 100%; height: 40px; border-radius: 999px; background: var(--surface); }
.toolbar .search input:focus { background: var(--surface); }
.toolbar .search .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-mute); width: 18px; height: 18px; pointer-events: none; }
@media (max-width: 640px) { .toolbar .search { max-width: none; } }
.chip { display: inline-flex; padding: 3px 10px; border-radius: 999px; background: var(--muted-soft); font-size: .8rem; font-weight: 600; color: var(--text-soft); }
.kv { display: grid; grid-template-columns: minmax(0, 140px) 1fr; gap: 10px 16px; font-size: .92rem; }
.kv dt { color: var(--text-mute); font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em;
  background: var(--muted-soft); color: var(--text); padding: 1px 6px; border-radius: 5px;
  overflow-wrap: anywhere; word-break: break-word; }
.divider { height: 1px; background: var(--border); margin: 20px 0; border: 0; }
.two-col { display: grid; grid-template-columns: minmax(0,1fr) 350px; gap: 20px; align-items: start; }
@media (min-width: 1600px) { .two-col { grid-template-columns: minmax(0,1fr) 400px; gap: 24px; } }
.mt-0{margin-top:0}.mb-0{margin-bottom:0}.text-soft{color:var(--text-soft)}.text-right{text-align:right}

/* ---------- Searchable select (combobox) ---------- */
.ss { position: relative; display: block; }
.ss__control {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: .92rem; font-family: inherit;
  cursor: pointer; text-align: left; line-height: 1.3;
}
.ss__control:hover { border-color: var(--text-mute); }
.ss__control.is-open { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--surface); }
.ss__value { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss__value.is-placeholder { color: var(--text-mute); }
.ss__caret { color: var(--text-mute); flex-shrink: 0; transition: transform .15s; }
.ss__control.is-open .ss__caret { transform: rotate(180deg); }
.ss__panel {
  position: fixed; z-index: 250; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  overflow: hidden; display: flex; flex-direction: column; max-height: 320px;
}
.ss__search { padding: 8px; border-bottom: 1px solid var(--border); position: relative; flex-shrink: 0; }
.ss__search .ic { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); color: var(--text-mute); pointer-events: none; }
.ss__search input {
  width: 100%; padding: 9px 10px 9px 36px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: .9rem; font-family: inherit;
}
.ss__search input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.ss__list { overflow-y: auto; padding: 5px; }
.ss__opt {
  padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ss__opt:hover, .ss__opt.is-active { background: var(--surface-2); }
.ss__opt.is-selected { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.ss__empty { padding: 16px; text-align: center; color: var(--text-mute); font-size: .88rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--primary-soft), var(--bg)); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px; }
.login-card .brand { display: flex; align-items: center; gap: 11px; font-weight: 800; font-size: 1.2rem; margin-bottom: 6px; }
.login-card .brand .logo { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-d)); color: #fff; }

/* ---------- Responsive ---------- */
.sidebar__overlay { display: none; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar__overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .main { margin-left: 0; }
  .burger { display: inline-flex; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}
