:root {
  --navy: #17324d;
  --navy-dark: #102638;
  --navy-soft: #e8eef4;
  --red: #b43c4c;
  --red-dark: #91303e;
  --teal: #157a78;
  --amber: #c17a18;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #dbe3eb;
  --surface: #ffffff;
  --canvas: #f3f6f9;
  --success: #16805c;
  --danger: #b42336;
  --shadow: 0 10px 30px rgba(22, 50, 77, 0.08);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  display: flex;
  width: 250px;
  flex-direction: column;
  padding: 24px 18px;
  color: #fff;
  background:
    radial-gradient(circle at 10% 10%, rgba(180, 60, 76, 0.32), transparent 26%),
    linear-gradient(180deg, var(--navy-dark), var(--navy));
  box-shadow: 10px 0 30px rgba(16, 38, 56, 0.12);
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 6px 30px; }
.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--red);
  box-shadow: 0 8px 18px rgba(180, 60, 76, .3);
  font-size: 22px;
  font-weight: 800;
}
.brand-mark.large { width: 58px; height: 58px; border-radius: 17px; font-size: 30px; }
.brand strong { display: block; letter-spacing: .12em; }
.brand small { display: block; margin-top: 2px; color: #b9c8d6; font-size: 11px; }
.main-nav { display: grid; gap: 7px; }
.main-nav a, .nav-logout {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  color: #cad7e2;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.main-nav a:hover, .nav-logout:hover { color: #fff; background: rgba(255, 255, 255, .08); transform: translateX(2px); }
.main-nav a.active { color: #fff; background: var(--red); box-shadow: 0 8px 20px rgba(180, 60, 76, .22); }
.nav-icon { display: inline-grid; width: 22px; place-items: center; font-size: 18px; }
.sidebar-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  background: rgba(255,255,255,.05);
}
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note small { color: #aebfce; font-size: 11px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #45d39d; box-shadow: 0 0 0 5px rgba(69,211,157,.12); }
.logout-form { margin-top: 10px; }
.page-frame { display: flex; min-height: 100vh; width: calc(100% - 250px); margin-left: 250px; flex-direction: column; }
.topbar {
  display: flex;
  min-height: 88px;
  align-items: center;
  gap: 18px;
  padding: 16px 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 { margin: 1px 0 0; color: var(--navy); font-size: clamp(21px, 2vw, 28px); line-height: 1.2; }
.eyebrow, .section-kicker {
  margin: 0;
  color: var(--red);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .16em;
}
.topbar-user { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.topbar-user strong, .topbar-user small { display: block; }
.topbar-user small { color: var(--muted); font-size: 11px; }
.avatar { display: inline-grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; color: #fff; background: var(--navy); font-weight: 800; }
.menu-toggle { display: none; border: 0; color: var(--navy); background: transparent; font-size: 24px; cursor: pointer; }
.page-content { width: 100%; max-width: 1680px; flex: 1; margin: 0 auto; padding: 28px 30px 40px; }
.app-footer { padding: 14px 30px 22px; color: var(--muted); font-size: 12px; text-align: center; }
.mobile-overlay { display: none; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.compact-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card {
  position: relative;
  min-height: 145px;
  overflow: hidden;
  padding: 22px;
  border-radius: 17px;
  color: #fff;
  box-shadow: var(--shadow);
}
.stat-card::after {
  position: absolute;
  width: 110px;
  height: 110px;
  right: -35px;
  bottom: -40px;
  border: 18px solid rgba(255,255,255,.08);
  border-radius: 50%;
  content: "";
}
.stat-card.navy { background: linear-gradient(135deg, #17324d, #264f71); }
.stat-card.red { background: linear-gradient(135deg, #a93345, #c85766); }
.stat-card.teal { background: linear-gradient(135deg, #126b69, #229b96); }
.stat-card.amber { background: linear-gradient(135deg, #a76612, #d89532); }
.stat-card .stat-label { display: block; color: rgba(255,255,255,.76); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stat-card strong { display: block; margin: 13px 0 4px; font-size: clamp(24px, 2vw, 32px); line-height: 1; }
.stat-card small { color: rgba(255,255,255,.72); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.panel, .form-card, .company-banner {
  border: 1px solid rgba(219, 227, 235, .9);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel { padding: 22px; }
.panel-header, .page-actions, .company-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.panel-header { margin-bottom: 18px; }
.panel-header h2, .form-section-heading h2, .company-banner h2 { margin: 2px 0 0; color: var(--navy); font-size: 19px; }
.text-link { color: var(--red); font-size: 12px; font-weight: 700; }
.compact-list { display: grid; gap: 2px; }
.compact-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 6px; border-bottom: 1px solid #edf1f5; }
.compact-row:last-child { border-bottom: 0; }
.compact-row:hover strong { color: var(--red); }
.compact-row span { min-width: 0; }
.compact-row strong, .compact-row small { display: block; }
.compact-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.compact-row b { flex: none; color: var(--red); }
.positive { color: var(--success) !important; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 22px; }
.quick-actions a { display: grid; grid-template-columns: 46px 1fr; column-gap: 14px; padding: 19px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.quick-actions a > span { grid-row: span 2; display: grid; width: 46px; height: 46px; place-items: center; border-radius: 12px; color: #fff; background: var(--navy); font-size: 22px; }
.quick-actions small { color: var(--muted); }
.quick-actions a:hover { border-color: #b7c7d6; transform: translateY(-1px); }

.page-actions { margin-bottom: 18px; }
.page-actions p { margin: 0; color: var(--muted); }
.button-group, .row-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
  transition: all .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--red); }
.button.primary:hover { background: var(--red-dark); }
.button.secondary { color: #fff; background: var(--navy); }
.button.debt-button { color: #fff; background: var(--amber); }
.button.debt-button:hover { background: #a96510; }
.button.ghost { color: var(--navy); border-color: var(--line); background: #fff; }
.button.wide { width: 100%; }
.icon-button {
  display: inline-flex;
  min-height: 31px;
  align-items: center;
  padding: 0 9px;
  border: 1px solid #cbd7e2;
  border-radius: 7px;
  color: var(--navy);
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}
.icon-button.accent { color: #fff; border-color: var(--navy); background: var(--navy); }
.icon-button.danger { color: var(--danger); border-color: #efc2c8; background: #fff7f8; }
.icon-button.success { color: var(--success); border-color: #b5dfd0; background: #f2fbf7; }
.icon-button.debt-action { color: #8a540d; border-color: #ebd09e; background: #fff8e9; }
.confirm-form { display: inline; margin: 0; }

.table-panel { padding: 17px; overflow: hidden; }
.table-scroll { width: 100%; overflow-x: auto; }
table.data-table { width: 100% !important; border-collapse: collapse !important; }
table.data-table thead th { color: #fff !important; background: var(--navy) !important; border-bottom: 0 !important; font-size: 11px; letter-spacing: .02em; white-space: nowrap; }
table.data-table tbody td { border-bottom: 1px solid #e8edf2 !important; vertical-align: middle; }
table.data-table tbody tr:hover td { background: #f7fafc !important; }
.wrap-cell { min-width: 220px; white-space: normal !important; }
.firms-table .firm-name-cell {
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  white-space: normal !important;
}
.firms-table .actions-column {
  width: 210px;
  min-width: 210px;
  max-width: 210px;
}
.firms-table .firm-row-actions {
  flex-wrap: nowrap;
  gap: 5px;
}
.firms-table .edit-button {
  color: #fff;
  border-color: var(--red);
  background: var(--red);
}
.firms-table .dtfc-fixed-start {
  background: #fff !important;
  box-shadow: 5px 0 10px rgba(16, 38, 56, .06);
}
.firms-table thead .dtfc-fixed-start {
  background: var(--navy) !important;
}
.dt-container .dt-search input, .dt-container .dt-length select {
  min-height: 36px;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  background: #fff !important;
}
.dt-container .dt-paging .dt-paging-button.current { color: #fff !important; border-color: var(--navy) !important; background: var(--navy) !important; }
.dt-layout-row { gap: 14px; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 999px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge.neutral { color: #455a70; background: #eaf0f5; }
.badge.success { color: #0b6848; background: #dcf6eb; }
.badge.warning { color: #88510c; background: #fff0d7; }
.money-balance { color: var(--red); font-weight: 800; }
.money-overpaid { color: var(--success); font-weight: 800; }
.debt-value { color: var(--red); }
.muted { color: var(--muted); }
.document-links { display: flex; gap: 4px; flex-wrap: wrap; }
.document-links a { padding: 3px 7px; border-radius: 6px; color: var(--navy); background: var(--navy-soft); font-size: 10px; font-weight: 700; }

.form-card { overflow: hidden; }
.form-card.narrow-form { max-width: 900px; margin: 0 auto; }
.form-section { padding: 26px; border-bottom: 1px solid var(--line); }
.form-section-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }
.form-section-heading > span { display: inline-grid; width: 38px; height: 38px; flex: none; place-items: center; border-radius: 10px; color: #fff; background: var(--navy); font-weight: 800; }
.form-section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: grid; min-width: 0; gap: 7px; color: var(--navy); font-size: 12px; font-weight: 700; }
.field.span-2, .span-2 { grid-column: span 2; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid #cbd6df;
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
  font-weight: 400;
  transition: border .18s ease, box-shadow .18s ease;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #6d8da8; box-shadow: 0 0 0 3px rgba(23, 50, 77, .09); }
.field small { color: var(--muted); font-weight: 400; }
.form-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 20px 26px; background: #f8fafc; }
.input-action-wrap, .password-wrap { display: flex; align-items: stretch; }
.input-action-wrap input, .password-wrap input { min-width: 0; border-radius: 9px 0 0 9px; }
.input-action, .password-toggle {
  padding: 0 10px;
  border: 1px solid #cbd6df;
  border-left: 0;
  color: var(--navy);
  background: #edf3f7;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}
.input-action:last-child, .password-toggle { border-radius: 0 9px 9px 0; }
.inventory-description { min-height: 90px; padding: 15px; border: 1px dashed #b9c9d7; border-radius: 10px; color: var(--muted); background: #f8fafc; white-space: pre-line; }
.inventory-description strong { display: block; margin-bottom: 6px; color: var(--navy); }
.inventory-description p { margin: 0; }
.select2-container { width: 100% !important; }
.select2-container .select2-selection--single { height: auto !important; min-height: 43px; padding: 6px; border-color: #cbd6df !important; border-radius: 9px !important; }
.select2-container .select2-selection--single .select2-selection__rendered { line-height: 29px !important; }
.select2-container .select2-selection--single .select2-selection__arrow { height: 41px !important; }
.file-field { padding: 15px; border: 1px dashed #b9c9d7; border-radius: 10px; background: #f8fafc; }
.file-field input { padding: 7px; background: #fff; }
.uploaded-documents { display: grid; gap: 9px; }
.uploaded-documents > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px; }
.uploaded-documents a strong, .uploaded-documents a small { display: block; }
.uploaded-documents a small { color: var(--muted); }

.company-banner { margin-bottom: 18px; padding: 22px; }
.company-banner h2 { margin-top: 7px; }
.company-banner p { margin: 5px 0 0; color: var(--muted); }
.flash-message, .form-alert { margin-bottom: 18px; padding: 13px 15px; border: 1px solid; border-radius: 10px; }
.flash-success { color: #0c6849; border-color: #b9e3d3; background: #eaf9f3; }
.form-alert.warning { color: #79500e; border-color: #efdaaf; background: #fff8e8; }
.form-alert.danger { color: #8f2634; border-color: #edbdc4; background: #fff2f4; }
.form-alert ul { margin: 7px 0 0; padding-left: 20px; }
.empty-state { padding: 35px; color: var(--muted); text-align: center; }
.empty-state.compact { padding: 28px 10px; }

.accounting-intro h2 { margin: 3px 0 2px; color: var(--navy); font-size: 20px; }
.accounting-intro > div > p:last-child { margin-top: 4px; }
.accounting-layout { display: block; }
.accounting-accounts { min-width: 0; }
.accounting-firm-cell { min-width: 300px; white-space: normal !important; }
.accounting-firm-cell strong, .accounting-firm-cell small { display: block; }
.accounting-firm-cell strong { color: var(--navy); }
.accounting-firm-cell small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.account-status { margin-right: 6px; font-weight: 800; }
.account-status.active { color: var(--success); }
.account-status.archived { color: var(--amber); }
.accounting-row-actions { min-width: 350px; flex-wrap: nowrap; }
.accounting-pdf-button { color: #fff; border-color: var(--navy); background: var(--navy); }
.recent-movements { min-width: 0; margin-top: 22px; padding: 18px; }
.movement-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 28px; }
.movement-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  border-bottom: 1px solid #edf1f5;
}
.movement-row:last-child { border-bottom: 0; }
.movement-row:hover .movement-copy strong { color: var(--red); }
.movement-kind { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 9px; font-size: 11px; font-weight: 900; }
.movement-kind.debt { color: #8a540d; background: #fff0d7; }
.movement-kind.payment { color: #0b6848; background: #dcf6eb; }
.movement-copy { min-width: 0; }
.movement-copy strong, .movement-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.movement-copy strong { color: var(--navy); font-size: 12px; }
.movement-copy small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.movement-row b { font-size: 12px; white-space: nowrap; }

.app-dialog { width: min(440px, calc(100% - 30px)); padding: 24px; border: 0; border-radius: 15px; box-shadow: 0 24px 70px rgba(16,38,56,.3); }
.app-dialog::backdrop { background: rgba(10, 24, 36, .58); }
.app-dialog h3 { margin: 0; color: var(--navy); font-size: 20px; }
.app-dialog p { color: var(--muted); }
.dialog-close { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 24px; }

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 20%, rgba(180,60,76,.16), transparent 25%),
    radial-gradient(circle at 90% 80%, rgba(21,122,120,.12), transparent 24%),
    #edf2f6;
}
.login-shell { display: grid; width: min(980px, 100%); min-height: 600px; grid-template-columns: 1.1fr .9fr; overflow: hidden; border-radius: 24px; background: #fff; box-shadow: 0 30px 90px rgba(16,38,56,.2); }
.login-panel { position: relative; display: flex; overflow: hidden; align-items: center; padding: 60px; color: #fff; background: linear-gradient(145deg, var(--navy-dark), var(--navy)); }
.login-brand { position: relative; z-index: 2; }
.login-brand .eyebrow { margin-top: 24px; color: #ef9aa5; }
.login-brand h1 { margin: 6px 0 14px; font-size: clamp(34px, 4vw, 54px); line-height: 1.02; }
.login-brand p:last-child { max-width: 410px; color: #c2d0db; font-size: 16px; }
.login-decoration span { position: absolute; border: 1px solid rgba(255,255,255,.08); border-radius: 50%; }
.login-decoration span:nth-child(1) { width: 330px; height: 330px; right: -150px; bottom: -100px; }
.login-decoration span:nth-child(2) { width: 240px; height: 240px; right: -105px; bottom: -55px; }
.login-decoration span:nth-child(3) { width: 150px; height: 150px; right: -60px; bottom: -10px; background: rgba(180,60,76,.15); }
.login-form-panel { display: grid; place-items: center; padding: 48px; }
.login-form { width: 100%; max-width: 340px; }
.login-heading { margin-bottom: 28px; }
.login-kicker { color: var(--red); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.login-heading h2 { margin: 7px 0 5px; color: var(--navy); font-size: 28px; }
.login-heading p { margin: 0; color: var(--muted); }
.login-form .field { margin-bottom: 17px; }
.login-security { display: block; margin-top: 14px; color: var(--muted); text-align: center; }

.error-page { max-width: 620px; margin: 8vh auto; padding: 50px; text-align: center; }
.error-page.standalone { width: min(620px, 100%); }
.error-code { display: block; color: var(--red); font-size: 64px; font-weight: 900; line-height: 1; }
.error-page h1, .error-page h2 { color: var(--navy); }
.error-page p { margin-bottom: 24px; color: var(--muted); }

@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .compact-stats { grid-template-columns: repeat(3, 1fr); }
  .quick-actions { grid-template-columns: 1fr; }
  .movement-list { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); }
  .sidebar.open { transform: translateX(0); }
  .page-frame { width: 100%; margin-left: 0; }
  .menu-toggle { display: inline-block; }
  .mobile-overlay.visible { position: fixed; inset: 0; z-index: 40; display: block; background: rgba(10,24,36,.5); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .login-shell { grid-template-columns: 1fr; }
  .login-panel { min-height: 250px; padding: 38px; }
  .login-brand h1 { font-size: 38px; }
}

@media (max-width: 680px) {
  .topbar { min-height: 72px; padding: 12px 16px; }
  .topbar .eyebrow, .topbar-user div { display: none; }
  .topbar-user { margin-left: auto; }
  .page-content { padding: 18px 14px 30px; }
  .stats-grid, .compact-stats { grid-template-columns: 1fr; }
  .stat-card { min-height: 125px; }
  .page-actions, .company-banner { align-items: flex-start; flex-direction: column; }
  .page-actions .button-group, .company-banner .button-group { width: 100%; }
  .page-actions .button, .company-banner .button { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2, .span-2 { grid-column: span 1; }
  .form-section { padding: 20px 16px; }
  .form-footer { padding: 16px; }
  .form-footer .button { flex: 1; }
  .login-body { padding: 10px; }
  .login-shell { min-height: calc(100vh - 20px); border-radius: 16px; }
  .login-panel { display: none; }
  .login-form-panel { padding: 30px 22px; }
}
