:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #637083;
  --line: #dce2ea;
  --line-strong: #c4ccd8;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --surface-tint: #eef4ff;
  --nav: #111827;
  --nav-soft: #1f2937;
  --accent: #1769e0;
  --accent-dark: #0d4ead;
  --accent-soft: #e8f1ff;
  --success: #147a4b;
  --success-soft: #e6f6ee;
  --warning: #9a5b08;
  --warning-soft: #fff4d9;
  --danger: #b42318;
  --danger-soft: #feebe9;
  --shadow: 0 16px 48px rgb(15 23 42 / 10%);
  --radius: 12px;
  --radius-sm: 8px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); color: var(--ink); background: var(--surface-soft); }
body { min-width: 320px; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: .82rem; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.break-all { overflow-wrap: anywhere; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(360px, 1.1fr);
  background: var(--surface);
}
.login-brand {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #0d1525, #1b2a45 68%, #164d9c);
  color: white;
  padding: clamp(34px, 7vw, 96px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
}
.login-brand::after {
  content: "";
  position: absolute;
  width: 420px;
  height: 420px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 50%;
  right: -180px;
  bottom: -110px;
  box-shadow: 0 0 0 60px rgb(255 255 255 / 3%), 0 0 0 120px rgb(255 255 255 / 2%);
}
.brand-lockup { display: flex; align-items: center; gap: 13px; position: relative; z-index: 1; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-weight: 800;
  letter-spacing: -.04em;
  background: white;
  color: #123b78;
  box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
}
.brand-copy strong { display: block; font-size: 1rem; }
.brand-copy span { display: block; color: #aebbd0; font-size: .82rem; margin-top: 2px; }
.login-brand-message { position: relative; z-index: 1; max-width: 600px; }
.login-brand-message h1 { font-size: clamp(2.3rem, 5vw, 4.5rem); line-height: .98; letter-spacing: -.055em; margin: 0 0 24px; }
.login-brand-message p { color: #c7d3e4; font-size: 1.06rem; line-height: 1.7; max-width: 510px; }
.login-version { color: #93a4be; font-size: .78rem; position: relative; z-index: 1; }
.login-panel { display: grid; place-items: center; padding: 32px; min-height: 100vh; }
.login-card { width: min(100%, 470px); }
.login-card h2 { font-size: 2rem; letter-spacing: -.035em; margin: 0 0 8px; }
.login-card > p { margin: 0 0 30px; color: var(--muted); line-height: 1.55; }
.auth-step { animation: fade-in .18s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.auth-key {
  border: 1px dashed #9fb5d2;
  background: #f3f7fd;
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 16px 0;
}
.auth-key-code { font: 700 1.08rem/1.5 ui-monospace, monospace; letter-spacing: .12em; overflow-wrap: anywhere; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
.recovery-code { background: #f2f4f7; border-radius: 6px; padding: 8px 10px; font: 600 .85rem ui-monospace, monospace; }

.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field label, .field-label { display: block; font-size: .82rem; font-weight: 650; color: #344054; margin-bottom: 7px; }
.field input, .field select, .field textarea, .control {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.field textarea { min-height: 92px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(23 105 224 / 13%); }
.field-help { color: var(--muted); font-size: .76rem; margin-top: 5px; line-height: 1.45; }
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-prefix input { padding-left: 27px; }
.checkbox-line { display: flex; align-items: flex-start; gap: 9px; margin: 10px 0; color: #344054; font-size: .88rem; }
.checkbox-line input { margin-top: 2px; }

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 13px;
  font-weight: 650;
  font-size: .86rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: #344054; }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; border-color: #aab4c2; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fac5c0; }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; }
.btn-small { min-height: 31px; padding: 5px 9px; font-size: .78rem; }
.btn-block { width: 100%; min-height: 45px; }
.btn-icon { width: 36px; padding: 0; }
.button-row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.button-row.end { justify-content: flex-end; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  background: var(--nav);
  color: #d7deea;
  display: flex;
  flex-direction: column;
  z-index: 30;
}
.sidebar .brand-lockup { padding: 19px 19px 17px; border-bottom: 1px solid rgb(255 255 255 / 8%); }
.sidebar .brand-mark { width: 36px; height: 36px; border-radius: 9px; }
.sidebar-nav { padding: 13px 10px; overflow-y: auto; flex: 1; }
.nav-section-label { color: #738198; text-transform: uppercase; letter-spacing: .1em; font-size: .65rem; font-weight: 700; margin: 18px 10px 7px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c3ccda;
  text-decoration: none;
  border-radius: 7px;
  padding: 9px 10px;
  margin: 2px 0;
  font-size: .87rem;
  font-weight: 550;
}
.nav-link:hover { background: rgb(255 255 255 / 6%); color: white; }
.nav-link.active { background: #244878; color: white; }
.nav-icon { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 6px; background: rgb(255 255 255 / 7%); font-size: .68rem; font-weight: 750; }
.sidebar-footer { border-top: 1px solid rgb(255 255 255 / 8%); padding: 13px; }
.sidebar-user { display: flex; gap: 10px; align-items: center; min-width: 0; }
.avatar { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; background: #2e5c98; color: white; font-weight: 750; font-size: .78rem; }
.sidebar-user-copy { min-width: 0; }
.sidebar-user-copy strong, .sidebar-user-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-copy strong { color: white; font-size: .79rem; }
.sidebar-user-copy span { color: #8391a6; font-size: .69rem; margin-top: 2px; }
.main-area { grid-column: 2; min-width: 0; }
.topbar {
  height: 64px;
  background: rgb(255 255 255 / 93%);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(9px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 11px; min-width: 0; }
.topbar-title { font-weight: 720; letter-spacing: -.02em; }
.company-select { width: min(280px, 30vw); min-height: 36px; padding: 6px 32px 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.mobile-menu { display: none; }
.content { padding: 24px; max-width: 1760px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin: 3px 0 21px; }
.page-header h1 { margin: 0; font-size: 1.72rem; letter-spacing: -.035em; }
.page-header p { margin: 6px 0 0; color: var(--muted); font-size: .9rem; }

.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: 13px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; min-width: 0; }
.stat-label { color: var(--muted); font-size: .74rem; font-weight: 650; }
.stat-value { font-size: 1.65rem; font-weight: 760; letter-spacing: -.04em; margin-top: 8px; overflow: hidden; text-overflow: ellipsis; }
.stat-note { color: var(--muted); font-size: .69rem; margin-top: 5px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card + .card { margin-top: 18px; }
.card-header { min-height: 55px; padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header h2, .card-header h3 { margin: 0; font-size: .97rem; }
.card-body { padding: 17px; }
.app-grid { display: grid; grid-template-columns: repeat(3, minmax(200px, 1fr)); gap: 13px; }
.app-card { border: 1px solid var(--line); border-radius: 10px; padding: 17px; background: white; text-decoration: none; color: var(--ink); transition: border-color .12s, box-shadow .12s; }
.app-card:hover { border-color: #9fb8db; box-shadow: 0 8px 24px rgb(15 23 42 / 7%); }
.app-card strong { display: block; font-size: .94rem; }
.app-card span { display: block; color: var(--muted); font-size: .77rem; line-height: 1.45; margin-top: 6px; }

.toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 13px; }
.toolbar .search { flex: 1 1 260px; max-width: 450px; }
.toolbar input, .toolbar select { min-height: 38px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 7px; background: white; }
.toolbar select { min-width: 130px; }
.toolbar-spacer { flex: 1; }
.table-card { background: white; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .8rem; }
th { background: #f7f9fc; color: #526075; font-size: .69rem; letter-spacing: .025em; text-transform: uppercase; font-weight: 720; text-align: left; white-space: nowrap; }
th, td { padding: 10px 12px; border-bottom: 1px solid #e8ecf2; vertical-align: middle; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: 0; }
td strong { font-weight: 660; }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.table-empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.table-empty strong { display: block; color: #344054; margin-bottom: 5px; }
.pagination { min-height: 50px; padding: 9px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); background: #fbfcfe; }
.pagination-info { color: var(--muted); font-size: .76rem; }
.pagination-controls { display: flex; gap: 6px; align-items: center; }

.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 22px; padding: 3px 7px; border-radius: 99px; font-size: .68rem; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-active, .badge-enabled, .badge-available { color: var(--success); background: var(--success-soft); }
.badge-draft, .badge-attention { color: var(--warning); background: var(--warning-soft); }
.badge-archived, .badge-disabled, .badge-suspended { color: var(--danger); background: var(--danger-soft); }
.badge-neutral { color: #526075; background: #edf0f5; }
.badge-fba { color: #7c3aed; background: #f2ebff; }
.badge-fbm { color: #075985; background: #e5f5ff; }
.chip-list { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { display: inline-flex; padding: 3px 7px; border-radius: 5px; background: #eef2f7; color: #475467; font-size: .68rem; }
.positive { color: var(--success); font-weight: 680; }
.negative { color: var(--danger); font-weight: 680; }

.detail-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.detail-list { display: grid; grid-template-columns: 150px 1fr; gap: 9px 13px; font-size: .82rem; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 550; }
.panel-soft { background: var(--surface-soft); border: 1px solid var(--line); border-radius: 9px; padding: 14px; }

.modal-backdrop { position: fixed; inset: 0; background: rgb(15 23 42 / 54%); z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal { width: min(100%, 660px); max-height: calc(100vh - 40px); background: white; border-radius: 13px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; animation: modal-in .13s ease-out; }
.modal-wide { width: min(100%, 900px); }
@keyframes modal-in { from { opacity: .4; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-header h2 { margin: 0; font-size: 1.08rem; }
.modal-header p { margin: 5px 0 0; color: var(--muted); font-size: .79rem; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer { padding: 13px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 9px; background: #fafbfc; }
.close-button { border: 0; background: transparent; color: var(--muted); font-size: 1.4rem; line-height: 1; padding: 0 3px; }
.form-error { background: var(--danger-soft); border: 1px solid #f6c3bf; color: var(--danger); padding: 10px 12px; border-radius: 7px; font-size: .8rem; margin-bottom: 14px; }
.info-box { background: var(--accent-soft); border: 1px solid #bdd4f5; color: #174478; padding: 12px 13px; border-radius: 8px; font-size: .8rem; line-height: 1.5; margin-bottom: 15px; }
.warning-box { background: var(--warning-soft); border: 1px solid #efd59d; color: #784308; padding: 12px 13px; border-radius: 8px; font-size: .8rem; line-height: 1.5; margin-bottom: 15px; }
.form-section { margin: 20px 0 11px; font-size: .78rem; color: #344054; font-weight: 750; text-transform: uppercase; letter-spacing: .055em; }
.component-row { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto; gap: 8px; align-items: end; margin-bottom: 9px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 300; display: flex; flex-direction: column; gap: 9px; width: min(390px, calc(100vw - 36px)); }
.toast { background: #172033; color: white; border-radius: 9px; padding: 12px 14px; box-shadow: var(--shadow); font-size: .82rem; display: flex; justify-content: space-between; gap: 12px; animation: toast-in .15s ease-out; }
.toast.error { background: #8f2119; }
.toast.success { background: #11643f; }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.loading { min-height: 300px; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 24px; height: 24px; border: 3px solid #dbe3ef; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1280px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .app-grid { grid-template-columns: repeat(2, minmax(200px, 1fr)); }
}
@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 230px; padding: 28px; }
  .login-brand-message h1 { font-size: 2.5rem; margin-top: 34px; }
  .login-brand-message p, .login-version { display: none; }
  .login-panel { min-height: auto; padding: 40px 24px; }
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main-area { min-width: 0; }
  .mobile-menu { display: inline-flex; }
  .content { padding: 18px; }
  .topbar { padding: 0 15px; }
  .company-select { width: 190px; max-width: 45vw; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .stats-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 9px; }
  .stat-card { padding: 13px; }
  .stat-value { font-size: 1.35rem; }
  .app-grid { grid-template-columns: 1fr; }
  .page-header { display: block; }
  .page-header .button-row { margin-top: 13px; }
  .toolbar { align-items: stretch; }
  .toolbar > * { flex: 1 1 auto; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .modal-backdrop { padding: 0; place-items: end center; }
  .modal { width: 100%; max-height: 94vh; border-radius: 14px 14px 0 0; }
  .component-row { grid-template-columns: 1fr 80px auto; }
  .recovery-grid { grid-template-columns: 1fr; }
}
