:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #17202a;
  --muted: #687586;
  --line: #dce3ea;
  --primary: #176b5d;
  --primary-dark: #0f4f45;
  --warning: #9a6700;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 18px 45px rgba(26, 40, 52, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  min-width: 0;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

img,
canvas,
svg {
  max-width: 100%;
}

.login-screen {
  align-items: center;
  background: #14212b;
  display: none;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 50;
}

.login-screen.active {
  display: flex;
}

body.auth-locked .app-shell {
  display: none;
}

.login-panel {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.3);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 24px;
  position: relative;
  width: 100%;
}

.login-close-btn {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  padding: 9px 12px;
  position: absolute;
  right: 14px;
  top: 14px;
}

.login-close-btn:hover {
  background: #eef3f7;
  border-color: #cbd7e2;
}

.login-brand {
  color: var(--text);
  margin-bottom: 6px;
  padding-right: 76px;
}

.login-brand span {
  color: var(--muted);
}

.login-version {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin: 0;
  text-align: center;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 268px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
  width: 100%;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 84px 1fr;
}

.sidebar {
  background: #101820;
  border-right: 1px solid #223241;
  border-radius: 0 18px 18px 0;
  box-shadow: 14px 0 36px rgba(16, 24, 32, 0.12);
  color: white;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: calc(100vh - 20px);
  margin: 10px 0 10px 10px;
  min-height: calc(100vh - 20px);
  overflow-y: auto;
  padding: 20px 16px;
  position: sticky;
  top: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 8px;
  padding: 10px;
  position: relative;
}

.brand-mark {
  align-items: center;
  background: #e8fff7;
  border: 1px solid rgba(79, 209, 177, 0.5);
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(79, 209, 177, 0.16);
  color: #0f4f45;
  display: flex;
  font-weight: 800;
  height: 44px;
  justify-content: center;
  letter-spacing: 0;
  width: 44px;
}

.brand strong,
.brand span {
  display: block;
}

.sidebar-brand strong {
  color: #f7fbff;
  font-size: 17px;
  letter-spacing: 0;
}

.sidebar-toggle {
  align-items: center;
  background: #1d2b36;
  border: 1px solid #33495a;
  border-radius: 8px;
  color: #f7fbff;
  display: flex;
  font-size: 18px;
  height: 30px;
  justify-content: center;
  margin-left: auto;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  width: 30px;
}

.sidebar-toggle:hover {
  background: #263947;
  border-color: #4fd1b1;
}

.brand span,
.storage-note span {
  color: #b8c5d1;
  font-size: 13px;
  margin-top: 2px;
}

.version-label {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 13px;
  min-height: 34px;
  align-items: center;
  padding: 5px 9px;
}

.nav {
  display: grid;
  gap: 6px;
  padding: 2px;
}

.nav-item {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #cbd8e3;
  display: flex;
  font-weight: 700;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  position: relative;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
  width: 100%;
}

.nav-item::before {
  align-items: center;
  background: #1a2833;
  border: 1px solid #293b49;
  border-radius: 8px;
  color: #9ddcca;
  content: attr(data-icon);
  display: inline-flex;
  flex: 0 0 30px;
  font-size: 15px;
  font-weight: 800;
  height: 30px;
  justify-content: center;
  line-height: 1;
  width: 30px;
}

.nav-item::after {
  background: #4fd1b1;
  border-radius: 999px;
  content: "";
  height: 22px;
  left: -18px;
  opacity: 0;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
}

.nav-item:hover,
.nav-item.active {
  background: #1b2a35;
  border-color: #304657;
  color: white;
}

.nav-item:hover {
  transform: translateX(2px);
}

.nav-item.active {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 22px rgba(0, 0, 0, 0.14);
}

.nav-item.active::before {
  background: #4fd1b1;
  border-color: #4fd1b1;
  color: #082019;
}

.nav-item.active::after {
  opacity: 1;
}

.sidebar-footer {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 8px;
  display: grid;
  gap: 9px;
  margin-top: auto;
  padding: 12px;
}

.sidebar-meta,
.sidebar-credit {
  background: transparent;
  border: 0;
  border-radius: 0;
  display: grid;
  gap: 2px;
  padding: 0;
}

.sidebar-meta span,
.sidebar-credit span {
  color: #93a8b8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar-meta strong,
.sidebar-credit strong {
  color: #f7fbff;
  font-size: 12px;
  line-height: 1.35;
}

.sidebar-credit {
  background: transparent;
  border-color: transparent;
}

.sidebar-collapsed .sidebar {
  align-items: center;
  gap: 18px;
  padding-left: 12px;
  padding-right: 12px;
}

.sidebar-collapsed .sidebar-brand {
  min-height: 62px;
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
  width: 100%;
}

.sidebar-collapsed .sidebar-brand strong,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .sidebar-footer {
  display: none;
}

.sidebar-collapsed .brand-mark {
  height: 50px;
  width: 50px;
}

.sidebar-collapsed .sidebar-toggle {
  background: #1d2b36;
  border-color: #33495a;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
  bottom: auto;
  font-size: 16px;
  height: 25px;
  margin-left: 0;
  position: absolute;
  right: -7px;
  top: -7px;
  width: 26px;
  z-index: 3;
}

.sidebar-collapsed .nav {
  width: 100%;
}

.sidebar-collapsed .nav-item {
  justify-content: center;
  min-height: 52px;
  padding: 7px;
}

.sidebar-collapsed .nav-item::before {
  flex-basis: 38px;
  font-size: 20px;
  height: 38px;
  width: 38px;
}

.sidebar-collapsed .nav-item::after {
  left: -14px;
}

.workspace {
  min-width: 0;
  padding: 30px;
  width: 100%;
}

.topbar {
  align-items: center;
  background: rgba(244, 246, 248, 0.96);
  border-bottom: 1px solid rgba(220, 227, 234, 0.9);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin: -30px -30px 24px;
  padding: 24px 30px 18px;
  position: sticky;
  top: 0;
  z-index: 15;
  backdrop-filter: blur(10px);
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.topbar-actions,
.panel-header {
  align-items: center;
  display: flex;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.runtime-pill {
  align-items: center;
  background: #e8f4f1;
  border: 1px solid #b7d8d0;
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  min-height: 32px;
  padding: 0 12px;
  text-transform: uppercase;
}

.runtime-pill[data-mode="web"] {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.sync-btn {
  background: #f8fbfd;
  border-color: #cfd9e3;
  font-weight: 800;
}

.primary-btn,
.ghost-btn,
.text-btn,
.small-btn {
  border-radius: 8px;
  border: 1px solid transparent;
  min-height: 38px;
  padding: 0 14px;
}

.primary-btn {
  background: var(--primary);
  color: white;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.danger-btn {
  background: var(--danger);
}

.danger-btn:hover {
  background: #991b1b;
}

.ghost-btn {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.text-btn {
  background: transparent;
  color: var(--primary);
  padding: 0 8px;
}

.small-btn {
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  min-height: 32px;
}

.danger-text {
  color: var(--danger);
}

.warning-copy {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #9a3412;
  font-size: 13px;
  font-weight: 700;
  margin: 0;
  padding: 12px;
}

.confirm-check {
  align-items: center;
  display: flex;
  gap: 10px;
}

.confirm-check input {
  min-height: auto;
  width: auto;
}

.file-btn {
  align-items: center;
  display: inline-flex;
  font: inherit;
  justify-content: center;
  text-align: center;
}

.file-btn input {
  display: none;
}

.smart-search-field {
  position: relative;
}

.smart-search-field:focus-within {
  z-index: 90;
}

.smart-search-box {
  align-items: center;
  display: flex;
  position: relative;
}

.smart-search-box .search-icon {
  color: var(--muted);
  font-size: 18px;
  left: 12px;
  line-height: 1;
  position: absolute;
  z-index: 1;
}

.smart-search-box input {
  padding-left: 38px;
}

.native-select-hidden {
  height: 1px;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  width: 1px;
}

.smart-suggestions {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(26, 40, 52, 0.16);
  display: none;
  left: 0;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 80;
}

.smart-suggestions.open {
  display: grid;
  gap: 4px;
}

.smart-suggestion {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  display: grid;
  gap: 2px;
  min-height: 44px;
  padding: 8px 10px;
  text-align: left;
}

.smart-suggestion:hover,
.smart-suggestion:focus {
  background: var(--surface-2);
}

.smart-suggestion strong {
  font-size: 14px;
}

.smart-suggestion span,
.smart-suggestion-empty {
  color: var(--muted);
  font-size: 12px;
}

.smart-suggestion-empty {
  padding: 10px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.retired-view {
  display: none !important;
}

.metric-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 20px;
}

#dashboard-view > .metric-grid,
#reports-view .report-grid > .panel:first-child {
  background: var(--bg);
  position: sticky;
  top: 94px;
  z-index: 12;
}

#dashboard-view > .metric-grid {
  padding-bottom: 12px;
}

#reports-view .report-grid > .panel:first-child {
  background: var(--surface);
}

.metric {
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-height: 132px;
  padding: 18px;
}

.metric.warning {
  border-left-color: var(--warning);
}

.metric.sales {
  border-left-color: #2563eb;
}

.metric.danger {
  border-left-color: var(--danger);
}

.metric.success {
  border-left-color: var(--success);
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 14px;
  font-weight: 800;
}

.metric strong {
  display: block;
  font-size: 26px;
  margin-top: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.35;
  margin-top: 6px;
}

.metric-icon {
  align-items: center;
  background: rgba(23, 107, 93, 0.1);
  border-radius: 999px;
  color: var(--primary) !important;
  display: inline-flex !important;
  flex: 0 0 auto;
  font-size: 18px !important;
  font-weight: 900;
  height: 48px;
  justify-content: center;
  width: 48px;
}

.metric.sales .metric-icon {
  background: #eff6ff;
  color: #2563eb !important;
}

.metric.warning .metric-icon {
  background: #fffaeb;
  color: var(--warning) !important;
}

.metric.danger .metric-icon {
  background: #fee4e2;
  color: var(--danger) !important;
}

.metric.success .metric-icon {
  background: #dcfae6;
  color: var(--success) !important;
}

.dashboard-grid,
.report-grid,
.settings-grid {
  display: grid;
  gap: 20px;
}

.dashboard-grid {
  grid-template-columns: 1.5fr 1fr;
}

#dashboard-view .panel {
  min-height: 0;
}

#dashboard-view .table-wrap {
  max-height: min(420px, calc(100dvh - 310px));
}

#dashboard-view .metric-grid {
  grid-template-columns: repeat(5, minmax(136px, 1fr));
  overflow-x: auto;
  scrollbar-gutter: stable;
}

.report-grid {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-tabs {
  align-items: end;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  display: flex;
  gap: 26px;
  grid-column: 1 / -1;
  overflow-x: auto;
  padding: 0 0 1px;
  scrollbar-width: thin;
}

.settings-tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 52px;
  padding: 8px 4px 15px;
  white-space: nowrap;
}

.settings-tab.active {
  background: transparent;
  border-bottom-color: #176b5d;
  box-shadow: none;
  color: var(--primary);
}

.settings-tab-hidden {
  display: none !important;
}

#settings-view .settings-grid > .panel:not(.settings-tab-hidden) {
  grid-column: 1 / -1;
}

.wide-panel {
  grid-column: 1 / -1;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 20px;
}

.report-grid > .panel,
.settings-grid > .panel {
  display: flex;
  flex-direction: column;
}

.section-kicker {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.panel-copy {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 8px 0 0;
}

.report-filters {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.report-filters label {
  min-width: 170px;
}

.report-tabs {
  align-items: end;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  display: flex;
  gap: 26px;
  margin-top: 14px;
  overflow-x: auto;
  padding: 0 0 1px;
  scrollbar-width: thin;
}

.report-tab {
  align-items: center;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  font: inherit;
  font-weight: 800;
  min-height: 52px;
  padding: 8px 4px 15px;
  white-space: nowrap;
}

.report-tab.active {
  background: transparent;
  border-bottom-color: var(--primary);
  box-shadow: none;
  color: var(--primary);
}

.report-tab span {
  align-items: center;
  background: rgba(23, 107, 93, 0.1);
  border-radius: 999px;
  display: inline-flex;
  font-size: 14px;
  height: 26px;
  justify-content: center;
  width: 26px;
}

.report-tab-hidden {
  display: none !important;
}

.report-metrics {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 26px;
}

.report-metric {
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 150px;
  padding: 22px;
}

.report-metric.success strong {
  color: var(--success);
}

.report-metric.warning strong {
  color: var(--warning);
}

.report-metric.primary strong {
  color: var(--primary);
}

.report-metric span,
.muted-label {
  color: var(--muted);
  font-size: 13px;
}

.report-metric strong {
  display: block;
  font-size: 22px;
  margin-top: 24px;
}

.report-metric small {
  color: var(--muted);
  display: block;
  font-size: 13px;
  line-height: 1.45;
  margin-top: 8px;
}

.report-metric-icon {
  align-items: center;
  background: rgba(23, 107, 93, 0.1);
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 18px;
  font-weight: 900;
  height: 56px;
  justify-content: center;
  width: 56px;
}

.report-metric.success .report-metric-icon {
  background: #dcfae6;
  color: var(--success);
}

.report-metric.warning .report-metric-icon {
  background: #fffaeb;
  color: var(--warning);
}

.report-metric.primary .report-metric-icon {
  background: rgba(23, 107, 93, 0.1);
  color: var(--primary);
}

.report-info-strip {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding: 14px 18px;
}

.report-info-strip span {
  align-items: center;
  border: 2px solid var(--primary);
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 900;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.report-info-strip p {
  margin: 0;
}

.chart-shell {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 6px;
  min-height: 270px;
  overflow: hidden;
  padding: 14px;
  position: relative;
  width: 100%;
}

#reports-view .panel:has(.chart-shell) {
  gap: 8px;
}

.chart-controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.chart-controls select {
  min-height: 34px;
  min-width: 120px;
  padding: 6px 9px;
}

.report-export-btn {
  align-self: end;
}

.print-report-header {
  display: none;
}

#service-movement-chart,
#client-movement-chart {
  display: block;
  max-width: 100%;
  width: 100%;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.form-panel {
  align-self: start;
  display: grid;
  gap: 13px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

input,
select,
textarea {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  min-height: 40px;
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

.search-input {
  max-width: 260px;
  width: 100%;
}

.search-box {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
}

.search-box span {
  color: var(--muted);
  font-size: 14px;
}

.search-box .search-input {
  border: 0;
  flex: 1;
  min-height: 38px;
  padding: 0;
}

.search-box .search-input:focus {
  outline: none;
}

.search-clear {
  align-items: center;
  background: #eef3f7;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  display: none;
  font-size: 15px;
  font-weight: 800;
  height: 22px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 22px;
}

.search-box.has-value .search-clear {
  display: flex;
}

.search-clear:hover {
  background: #dce6ee;
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
}

.view > .panel,
.report-grid > .panel:has(.table-wrap) {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 142px);
  overflow: hidden;
}

.view > .panel > .panel-header,
.view > .panel > .service-summary-grid,
.view > .panel > .subscription-summary-grid,
.view > .panel > .pagination-bar,
.report-grid > .panel:has(.table-wrap) > .panel-header {
  flex: 0 0 auto;
}

.view > .panel > .table-wrap,
.report-grid > .panel:has(.table-wrap) > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}

.view > .panel > .table-wrap thead th,
.report-grid > .panel:has(.table-wrap) > .table-wrap thead th {
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
  position: sticky;
  top: 0;
  z-index: 4;
}

.pagination-bar {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 10px;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 12px;
}

.pagination-actions {
  display: flex;
  gap: 8px;
}

.pagination-bar .small-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.table-wrap td .actions {
  align-items: center;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  white-space: nowrap;
}

.table-wrap td .actions .small-btn {
  flex: 0 0 auto;
}

.subscription-client-cell {
  min-width: 190px;
}

.subscription-client-cell .account-id,
.subscription-client-cell .subscriber-name {
  display: block;
}

.subscription-client-cell .account-id {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.subscription-client-cell .subscriber-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  margin-top: 3px;
}

.subscription-actions-cell {
  min-width: 282px;
}

.subscription-actions {
  flex-wrap: nowrap;
  justify-content: flex-start;
  white-space: nowrap;
}

.subscription-actions .small-btn {
  flex: 0 0 auto;
  min-width: auto;
  padding: 0 9px;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
}

.badge.active,
.badge.paid,
.badge.done {
  background: #dcfae6;
  color: var(--success);
}

.badge.due,
.badge.pending,
.badge.paused,
.badge.partial {
  background: #fef0c7;
  color: var(--warning);
}

.badge.overdue,
.badge.cancelled {
  background: #fee4e2;
  color: var(--danger);
}

.compact-list {
  display: grid;
  gap: 10px;
}

.compact-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.compact-item strong,
.compact-item span {
  display: block;
}

.compact-item span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.report-lines,
.tool-list,
.settings-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

#settings-view .tool-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: center;
  margin-top: 26px;
  padding: 18px 20px;
}

#settings-view .tool-list .primary-btn,
#settings-view .tool-list .ghost-btn,
#settings-view .file-btn {
  background: var(--surface);
  border-color: var(--primary);
  color: var(--primary);
  min-height: 46px;
  min-width: 176px;
}

#settings-view .tool-list .primary-btn {
  box-shadow: none;
}

.user-form {
  align-items: end;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.password-form {
  align-items: end;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.branding-form {
  align-items: end;
  grid-template-columns: minmax(160px, 260px) auto;
}

.branding-form input {
  text-transform: uppercase;
}

.admin-hidden {
  display: none !important;
}

.helper-text {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.message-template-form {
  align-items: start;
}

.message-template-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.message-template-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.message-template-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.message-template-card textarea {
  background: var(--surface);
}

.activity-log-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.activity-log-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
  max-height: 360px;
}

.database-stats-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-top: 14px;
}

.backup-status-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 20px;
}

.backup-status-card {
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 178px;
  min-width: 0;
  padding: 22px;
}

.backup-status-card span {
  color: var(--muted);
  display: block;
  font-size: 14px;
  font-weight: 800;
}

.backup-status-card strong {
  display: block;
  font-size: 22px;
  margin-top: 28px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.backup-status-card small {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 8px;
}

.backup-status-card.success strong {
  color: var(--success);
}

.backup-status-card.primary strong {
  color: var(--primary);
}

.backup-status-card.accent strong {
  color: #6f3cc3;
}

.backup-status-icon {
  align-items: center;
  border-radius: 999px;
  display: flex !important;
  flex: 0 0 auto;
  font-size: 24px !important;
  height: 56px;
  justify-content: center;
  width: 56px;
}

.backup-status-card.success .backup-status-icon {
  background: #dcfae6;
  color: var(--success);
}

.backup-status-card.primary .backup-status-icon {
  background: #e8f1ff;
  color: var(--primary);
}

.backup-status-card.accent .backup-status-icon {
  background: #f0e8ff;
  color: #6f3cc3;
}

.backup-status-card.warning .backup-status-icon {
  background: #fff4d7;
  color: #b77900;
}

.backup-status-card.warning strong {
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  margin-top: 52px;
  white-space: normal;
}

.backup-status-card.warning small {
  display: none;
}

.settings-action-btn,
.file-btn {
  align-items: center;
  display: inline-flex !important;
  gap: 10px;
  justify-content: center;
}

.settings-action-btn span,
.file-btn span {
  color: currentColor;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.settings-info-strip {
  align-items: center;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  gap: 14px;
  margin-top: 18px;
  padding: 18px 20px;
}

.settings-info-strip span {
  align-items: center;
  border: 2px solid var(--primary);
  border-radius: 999px;
  color: var(--primary);
  display: flex;
  flex: 0 0 auto;
  font-weight: 900;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.about-update-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 14px;
}

.about-update-card,
.release-note-card,
.update-instructions-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 14px;
}

.about-update-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.about-update-card strong {
  display: block;
  font-size: 15px;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.release-note-card,
.update-instructions-card {
  margin-top: 12px;
}

.update-choice-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.update-choice-grid .update-instructions-card {
  margin-top: 0;
}

.update-type-badge {
  background: rgba(23, 107, 93, 0.1);
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  font-size: 11px;
  font-weight: 900;
  margin-bottom: 10px;
  padding: 5px 9px;
  text-transform: uppercase;
}

.release-note-card h3,
.update-instructions-card h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

.release-note-card ul {
  color: var(--text);
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.update-instructions-card p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.database-stat-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px;
}

.database-stat-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.database-stat-card strong {
  display: block;
  font-size: 20px;
  margin-top: 6px;
}

.recycle-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 14px 0;
}

.recycle-summary-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px;
}

.recycle-summary-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.recycle-summary-card strong {
  display: block;
  font-size: 20px;
  margin-top: 6px;
}

.web-access-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 14px;
  padding: 14px;
}

.web-access-card input {
  font-weight: 800;
}

.web-access-actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.report-lines div {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) max-content;
  padding: 10px 0;
}

.report-lines span {
  color: var(--muted);
}

.report-lines strong {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.tool-list .ghost-btn {
  justify-self: stretch;
  text-align: center;
}

.hide {
  display: none;
}

.modal-backdrop {
  align-items: center;
  background: rgba(10, 20, 28, 0.58);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(12, 24, 35, 0.28);
  max-height: min(780px, calc(100dvh - 48px));
  max-width: 560px;
  overflow: auto;
  padding: 18px;
  width: 100%;
}

.large-modal {
  max-width: 1120px;
}

.modal-header,
.modal-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 14px;
}

.modal-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  margin-top: 4px;
  padding-top: 14px;
}

.restore-summary-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.restore-summary-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 12px;
}

.restore-summary-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.restore-summary-card strong {
  display: block;
  font-size: 16px;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.restore-summary-card.success {
  background: #ecfdf3;
  border-color: #abefc6;
}

.restore-summary-card.warning {
  background: #fffaeb;
  border-color: #fedf89;
}

.restore-compare-row {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 8px;
}

.restore-compare-row small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.restore-summary-card em {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  margin-top: 8px;
}

.report-preview-modal {
  max-width: 980px;
}

.report-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.report-preview-content {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: min(640px, calc(100dvh - 220px));
  overflow: auto;
  padding: 16px;
}

.preview-document {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  margin: 0 auto;
  max-width: 860px;
  padding: 22px;
}

.preview-document-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 12px;
}

.preview-document-header strong,
.preview-document-header span,
.preview-document-header small {
  display: block;
}

.preview-document-header strong {
  font-size: 24px;
}

.preview-document-header span,
.preview-document-header small {
  color: var(--muted);
  margin-top: 4px;
}

.preview-metrics,
.preview-chart-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.preview-metrics article,
.preview-chart-grid article {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.preview-metrics span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.preview-metrics strong {
  display: block;
  font-size: 17px;
  margin-top: 5px;
}

.preview-chart-grid img {
  display: block;
  max-height: 240px;
  object-fit: contain;
  width: 100%;
}

.preview-document h3 {
  font-size: 16px;
  margin: 16px 0 8px;
}

.client-profile {
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 16px;
}

.client-profile h3 {
  font-size: 22px;
  margin: 0;
}

.client-profile p {
  color: var(--muted);
  margin: 7px 0 0;
}

.client-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.subscription-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  margin-bottom: 16px;
}

.service-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.client-summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 13px;
}

.subscription-summary-card,
.subscription-detail-card,
.service-summary-card,
.service-detail-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 13px;
}

.client-summary-card.success {
  border-left-color: var(--success);
}

.subscription-summary-card.success,
.subscription-detail-card.success,
.service-summary-card.success,
.service-detail-card.success {
  border-left-color: var(--success);
}

.client-summary-card.warning {
  border-left-color: var(--warning);
}

.subscription-summary-card.warning,
.subscription-detail-card.warning,
.service-summary-card.warning,
.service-detail-card.warning {
  border-left-color: var(--warning);
}

.client-summary-card.danger {
  border-left-color: var(--danger);
}

.subscription-summary-card.danger,
.subscription-detail-card.danger,
.service-summary-card.danger,
.service-detail-card.danger {
  border-left-color: var(--danger);
}

.client-summary-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.subscription-summary-card span,
.subscription-detail-card span,
.service-summary-card span,
.service-detail-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.client-summary-card strong {
  display: block;
  font-size: 20px;
  margin-top: 7px;
}

.subscription-summary-card strong,
.subscription-detail-card strong,
.service-summary-card strong,
.service-detail-card strong {
  display: block;
  font-size: 18px;
  margin-top: 7px;
}

.subscription-profile {
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 16px;
}

.service-profile {
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 16px;
}

.subscription-profile h3 {
  font-size: 22px;
  margin: 0;
}

.service-profile h3 {
  font-size: 22px;
  margin: 0;
}

.subscription-profile p {
  color: var(--muted);
  margin: 7px 0 0;
}

.service-profile p {
  color: var(--muted);
  margin: 7px 0 0;
}

.subscription-detail-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 16px;
}

.service-detail-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.detail-actions-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.client-detail-section {
  border-top: 1px solid var(--line);
  padding: 16px 0 0;
}

.client-detail-section + .client-detail-section {
  margin-top: 16px;
}

.client-detail-section h3 {
  font-size: 16px;
  margin: 0 0 10px;
}

.client-detail-section p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.mini-table th,
.mini-table td {
  font-size: 13px;
  padding: 10px 8px;
}

.icon-btn {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: flex;
  font-size: 22px;
  height: 36px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 36px;
}

.toast {
  background: #14212b;
  border-radius: 8px;
  bottom: 22px;
  color: white;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .sidebar {
    align-items: center;
    border-radius: 0 16px 16px 0;
    box-shadow: 12px 0 28px rgba(16, 24, 32, 0.12);
    gap: 16px;
    height: calc(100dvh - 16px);
    margin: 8px 0 8px 8px;
    max-height: calc(100dvh - 16px);
    min-height: calc(100dvh - 16px);
    overflow-y: auto;
    padding: 14px 10px;
    position: sticky;
    top: 8px;
  }

  .sidebar-brand {
    justify-content: center;
    min-height: 58px;
    padding: 8px 0;
    width: 100%;
  }

  .sidebar-brand strong,
  .nav-label,
  .sidebar-footer {
    display: none;
  }

  .brand-mark {
    height: 46px;
    width: 46px;
  }

  .sidebar-toggle {
    display: none;
  }

  .nav {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .nav-item {
    justify-content: center;
    min-height: 50px;
    padding: 7px;
    text-align: center;
  }

  .nav-item::before {
    flex-basis: 36px;
    font-size: 19px;
    height: 36px;
    width: 36px;
  }

  .nav-item::after {
    display: none;
  }

  .workspace {
    padding: 20px;
  }

  .topbar {
    margin: -20px -20px 20px;
    padding: 20px;
    top: 0;
  }

  .metric-grid,
  .dashboard-grid,
  .report-grid,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #dashboard-view .metric-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    overflow: visible;
  }

  .dashboard-grid,
  .report-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-tabs {
    gap: 22px;
  }

  .client-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .subscription-summary-grid,
  .subscription-detail-grid,
  .service-summary-grid,
  .service-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 640px) {
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .sidebar {
    border-radius: 0 14px 14px 0;
    gap: 10px;
    height: calc(100dvh - 12px);
    margin: 6px 0 6px 6px;
    max-height: calc(100dvh - 12px);
    min-height: calc(100dvh - 12px);
    padding: 10px 8px;
    top: 6px;
  }

  .sidebar-brand {
    min-height: 52px;
    padding: 6px 0;
  }

  .brand-mark {
    height: 40px;
    width: 40px;
  }

  .workspace {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    margin: -12px -12px 12px;
    padding: 9px 10px;
    top: 0;
  }

  #dashboard-view > .metric-grid,
  #reports-view .report-grid > .panel:first-child {
    top: 146px;
  }

  #reports-view .report-grid > .panel:first-child {
    position: static;
  }

  .view > .panel,
  .report-grid > .panel:has(.table-wrap) {
    max-height: calc(100dvh - 164px);
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    justify-content: stretch;
  }

  .topbar-actions .primary-btn,
  .topbar-actions .ghost-btn,
  .runtime-pill {
    width: 100%;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .nav-item {
    justify-content: center;
    min-height: 44px;
    padding: 6px;
    text-align: center;
  }

  .nav-item::before {
    flex-basis: 32px;
    font-size: 18px;
    height: 32px;
    width: 32px;
  }

  .panel {
    padding: 12px;
  }

  .panel-header {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
  }

  .panel-actions,
  .chart-controls {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  #clients-view .panel-actions,
  #services-view .panel-actions {
    grid-template-columns: minmax(0, 1fr) max-content;
  }

  #subscriptions-view .panel-actions {
    grid-template-columns: minmax(0, 1fr) max-content;
  }

  #subscriptions-view .panel-actions .search-box {
    grid-column: 1 / -1;
  }

  .panel-actions > *,
  .chart-controls > *,
  .search-box,
  .search-input {
    max-width: none;
    width: 100%;
  }

  .pagination-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-controls {
    justify-content: space-between;
  }

  .pagination-controls .small-btn {
    flex: 1;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #dashboard-view .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 10px;
    padding-bottom: 6px;
  }

  #dashboard-view .dashboard-grid {
    gap: 12px;
  }

  #dashboard-view .table-wrap {
    max-height: calc(100dvh - 292px);
  }

  #dashboard-view .table-wrap table,
  #dashboard-view .table-wrap tbody,
  #dashboard-view .table-wrap tr,
  #dashboard-view .table-wrap td {
    display: block;
    width: 100%;
  }

  #dashboard-view .table-wrap thead {
    display: none;
  }

  #dashboard-view .table-wrap tbody {
    display: grid;
    gap: 8px;
  }

  #dashboard-view .table-wrap tr {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
  }

  #dashboard-view .table-wrap td {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(86px, 0.75fr) minmax(0, 1.25fr);
    min-height: 30px;
    padding: 6px 0;
    white-space: normal;
  }

  #dashboard-view .table-wrap td:last-child {
    border-bottom: 0;
  }

  #dashboard-view .table-wrap td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  #dashboard-view .table-wrap td[colspan] {
    display: block;
    text-align: center;
  }

  #dashboard-view .table-wrap td[colspan]::before {
    content: "";
    display: none;
  }

  .metric {
    gap: 8px;
    min-height: 92px;
    padding: 9px 10px;
  }

  .metric span {
    font-size: 11px;
    font-weight: 700;
    line-height: 1.25;
  }

  .metric strong,
  .report-metric strong {
    font-size: 17px;
  }

  .metric strong {
    margin-top: 8px;
  }

  .metric small {
    font-size: 10px;
    margin-top: 3px;
  }

  .metric-icon {
    font-size: 13px !important;
    height: 34px;
    width: 34px;
  }

  .primary-btn,
  .ghost-btn,
  .text-btn,
  .small-btn,
  input,
  select,
  textarea,
  .search-box {
    border-radius: 7px;
    font-size: 13px;
    min-height: 34px;
  }

  .primary-btn,
  .ghost-btn,
  .text-btn {
    padding-left: 10px;
    padding-right: 10px;
  }

  .small-btn {
    min-height: 30px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .search-box .search-input {
    min-height: 32px;
  }

  label {
    font-size: 12px;
    gap: 5px;
  }

  .report-metrics {
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 12px;
  }

  .report-tabs {
    gap: 18px;
    margin-top: 10px;
  }

  .report-metric {
    min-height: 128px;
    padding: 12px;
  }

  .report-metric span,
  .muted-label {
    font-size: 11px;
    line-height: 1.25;
  }

  .report-metric strong {
    font-size: 16px;
    margin-top: 4px;
  }

  .report-metric small {
    font-size: 11px;
    margin-top: 5px;
  }

  .report-metric-icon {
    font-size: 14px;
    height: 42px;
    width: 42px;
  }

  .report-info-strip {
    align-items: flex-start;
    padding: 12px;
  }

  #reports-view .panel:has(.chart-shell) {
    padding: 12px;
  }

  #reports-view .panel:has(.chart-shell) .panel-header {
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 6px;
  }

  #reports-view .panel:has(.chart-shell) .panel-header h2 {
    line-height: 1.2;
  }

  .chart-shell {
    min-height: 350px;
    padding: 10px;
  }

  .about-update-grid,
  .backup-status-grid,
  .database-stats-grid,
  .recycle-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .backup-status-grid {
    gap: 10px;
    grid-template-columns: 1fr;
  }

  #settings-view .panel {
    gap: 0;
  }

  #settings-view .panel-copy {
    font-size: 12px;
    line-height: 1.35;
  }

  #settings-view .tool-list {
    gap: 8px;
    margin-top: 10px;
  }

  #settings-view .tool-list .primary-btn,
  #settings-view .tool-list .ghost-btn,
  #settings-view .file-btn {
    min-height: 36px;
    width: 100%;
  }

  .branding-form {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .about-update-card,
  .backup-status-card,
  .database-stat-card {
    padding: 9px 10px;
  }

  .backup-status-card {
    align-items: center;
    min-height: 86px;
    padding: 12px 14px;
  }

  .about-update-card span,
  .backup-status-card span,
  .database-stat-card span {
    font-size: 11px;
    line-height: 1.25;
  }

  .about-update-card strong,
  .backup-status-card strong,
  .database-stat-card strong {
    font-size: 16px;
    margin-top: 4px;
  }

  .backup-status-card small {
    font-size: 11px;
    margin-top: 4px;
  }

  .backup-status-icon {
    font-size: 18px !important;
    height: 44px;
    width: 44px;
  }

  .message-template-grid {
    grid-template-columns: 1fr;
  }

  .update-choice-grid {
    grid-template-columns: 1fr;
  }

  .web-access-card {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .web-access-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .web-access-actions .primary-btn,
  .web-access-actions .ghost-btn {
    width: 100%;
  }

  .message-template-card {
    padding: 10px;
  }

  .message-template-card textarea {
    min-height: 112px;
  }

  .user-form {
    grid-template-columns: 1fr;
  }

  .password-form {
    grid-template-columns: 1fr;
  }

  .report-filters {
    align-items: stretch;
    flex-direction: column;
  }

  .report-filters label {
    min-width: 0;
    width: 100%;
  }

  .chart-shell {
    min-height: 300px;
  }

  #reports-view .panel-header .muted-label {
    display: block;
  }

  #reports-view .report-grid > .panel:has(.table-wrap) {
    max-height: none;
  }

  #reports-view .report-grid > .panel:has(.table-wrap) > .table-wrap {
    overflow: visible;
  }

  #reports-view .table-wrap table,
  #reports-view .table-wrap tbody,
  #reports-view .table-wrap tr,
  #reports-view .table-wrap td {
    display: block;
    width: 100%;
  }

  #reports-view .table-wrap thead {
    display: none;
  }

  #reports-view .table-wrap tbody {
    display: grid;
    gap: 8px;
  }

  #reports-view .table-wrap tr {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
  }

  #reports-view .table-wrap td {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(86px, 0.8fr) minmax(0, 1.2fr);
    min-height: 30px;
    padding: 6px 0;
    white-space: normal;
  }

  #reports-view .table-wrap td:last-child {
    border-bottom: 0;
  }

  #reports-view .table-wrap td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  #reports-view .table-wrap td[colspan] {
    display: block;
    text-align: center;
  }

  #reports-view .table-wrap td[colspan]::before {
    content: "";
    display: none;
  }

  #clients-view .table-wrap td:last-child,
  #services-view .table-wrap td:last-child,
  #subscriptions-view .subscription-actions-cell {
    min-width: 0;
  }

  #clients-view .table-wrap td:last-child .actions,
  #services-view .table-wrap td:last-child .actions,
  #subscriptions-view .subscription-actions {
    background: rgba(23, 107, 93, 0.06);
    border: 1px solid rgba(23, 107, 93, 0.14);
    border-radius: 8px;
    padding: 6px;
  }

  #clients-view .table-wrap td:last-child .small-btn,
  #services-view .table-wrap td:last-child .small-btn,
  #subscriptions-view .subscription-actions .small-btn {
    min-height: 30px;
    padding-left: 9px;
    padding-right: 9px;
  }

  .client-profile {
    flex-direction: column;
  }

  .client-summary-grid {
    grid-template-columns: 1fr;
  }

  .subscription-profile,
  .service-profile,
  .detail-actions-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .subscription-detail-grid,
  .service-detail-grid {
    grid-template-columns: 1fr;
  }

  #subscriptions-view .subscription-summary-grid {
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #subscriptions-view .subscription-summary-card {
    min-height: 58px;
    padding: 7px 8px;
  }

  #subscriptions-view .subscription-summary-card span {
    font-size: 10px;
    line-height: 1.25;
    white-space: nowrap;
  }

  #subscriptions-view .subscription-summary-card strong {
    font-size: 14px;
    line-height: 1.15;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #subscriptions-view .subscription-actions-cell {
    min-width: 304px;
  }

  #subscriptions-view .subscription-actions {
    display: flex;
    flex-wrap: nowrap;
    white-space: nowrap;
  }

  #services-view .service-summary-grid {
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #services-view .service-summary-card {
    padding: 9px 10px;
  }

  #services-view .service-summary-card span {
    font-size: 11px;
    line-height: 1.25;
  }

  #services-view .service-summary-card strong {
    font-size: 16px;
    margin-top: 4px;
  }

  h1 {
    font-size: 19px;
  }

  h2 {
    font-size: 15px;
  }

  .eyebrow {
    font-size: 11px;
    margin-bottom: 3px;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .modal {
    max-height: calc(100dvh - 20px);
    max-width: none;
    padding: 14px;
  }

  .modal-header,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions .primary-btn,
  .modal-actions .ghost-btn,
  .modal-actions .text-btn,
  .modal-actions .danger-btn {
    width: 100%;
  }

  .login-screen {
    padding: 14px;
  }

  .login-panel {
    padding: 18px;
  }

  .login-brand {
    padding-right: 70px;
  }

  th,
  td {
    font-size: 12px;
    padding: 7px 6px;
  }
}

@media (max-width: 420px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .sidebar {
    padding-left: 6px;
    padding-right: 6px;
  }

  .brand-mark {
    height: 36px;
    width: 36px;
  }

  .nav-item::before {
    flex-basis: 30px;
    font-size: 17px;
    height: 30px;
    width: 30px;
  }

  .topbar-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions .primary-btn,
  .topbar-actions .ghost-btn {
    min-height: 32px;
  }

  #clients-view .panel-actions,
  #services-view .panel-actions,
  #subscriptions-view .panel-actions {
    gap: 7px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #clients-view .panel-actions .primary-btn,
  #services-view .panel-actions .primary-btn,
  #subscriptions-view .panel-actions .primary-btn {
    min-height: 32px;
    padding-left: 8px;
    padding-right: 8px;
    white-space: nowrap;
  }

  #subscriptions-view .panel-actions select {
    min-width: 0;
  }

  #dashboard-view > .metric-grid,
  #reports-view .report-grid > .panel:first-child {
    top: 176px;
  }

  #reports-view .report-grid > .panel:first-child {
    position: static;
  }

  #dashboard-view > .metric-grid {
    top: 142px;
  }

  #dashboard-view .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #dashboard-view .metric {
    min-height: 86px;
  }

  #dashboard-view .metric strong {
    margin-top: 5px;
    text-align: left;
  }

  .view > .panel,
  .report-grid > .panel:has(.table-wrap) {
    max-height: calc(100dvh - 176px);
  }

  #dashboard-view .table-wrap {
    max-height: calc(100dvh - 300px);
  }

  #reports-view .report-metrics {
    grid-template-columns: 1fr;
  }

  #reports-view .report-metric {
    min-height: 116px;
    padding: 10px;
  }

  #reports-view .report-tabs {
    gap: 14px;
  }

  #reports-view .panel:has(.chart-shell) {
    padding: 10px;
  }

  .chart-shell {
    min-height: 372px;
    padding: 8px;
  }

  .about-update-grid,
  .backup-status-grid,
  .database-stats-grid,
  .recycle-summary-grid,
  .restore-summary-grid {
    grid-template-columns: 1fr;
  }

  .restore-compare-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .backup-status-card {
    min-height: 82px;
  }

  .settings-tabs {
    grid-template-columns: 1fr;
  }

  #settings-view .tool-list .primary-btn,
  #settings-view .tool-list .ghost-btn,
  #settings-view .file-btn,
  #settings-view .settings-form .primary-btn,
  .web-access-actions .primary-btn,
  .web-access-actions .ghost-btn {
    min-height: 34px;
  }

  #services-view .service-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #subscriptions-view .subscription-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #subscriptions-view .subscription-summary-card {
    min-height: 54px;
    padding: 6px 7px;
  }

  #subscriptions-view .subscription-summary-card span {
    font-size: 9px;
  }

  #subscriptions-view .subscription-summary-card strong {
    font-size: 13px;
  }

  .small-btn,
  .primary-btn,
  .ghost-btn,
  .text-btn {
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media print {
  @page {
    margin: 12mm;
    size: A4;
  }

  body,
  body.auth-locked {
    background: #ffffff !important;
    color: #101828;
  }

  .login-screen,
  .sidebar,
  .topbar,
  .toast,
  .modal-backdrop,
  .report-filters,
  .report-info-strip,
  .report-tabs,
  .report-export-btn,
  .pagination-bar {
    display: none !important;
  }

  .app-shell,
  .workspace {
    display: block !important;
    min-height: 0;
  }

  .workspace {
    height: auto;
    overflow: visible;
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #reports-view {
    display: block !important;
  }

  #reports-view .report-grid {
    display: block;
  }

  #reports-view .panel {
    border: 1px solid #d0d5dd;
    box-shadow: none;
    margin: 0 0 12px;
    page-break-inside: avoid;
    padding: 12px;
  }

  #reports-view .panel-header {
    margin-bottom: 10px;
  }

  #reports-view .panel-header h2 {
    font-size: 16px;
  }

  .print-report-header {
    border-bottom: 1px solid #d0d5dd;
    display: block;
    margin-bottom: 12px;
    padding-bottom: 10px;
  }

  .print-report-header strong,
  .print-report-header span {
    display: block;
  }

  .print-report-header strong {
    font-size: 22px;
  }

  .print-report-header span {
    color: #475467;
    font-size: 12px;
    margin-top: 4px;
  }

  .report-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .report-metric,
  .report-metric.success,
  .report-metric.warning {
    background: #ffffff;
    border-color: #d0d5dd;
    padding: 10px;
  }

  .report-metric strong {
    font-size: 18px;
  }

  .chart-shell {
    min-height: 210px;
  }

  table {
    font-size: 11px;
  }

  th,
  td {
    padding: 7px 8px;
  }

  body.printing-report-preview .app-shell,
  body.printing-report-preview .login-screen,
  body.printing-report-preview .modal-header,
  body.printing-report-preview .report-preview-actions {
    display: none !important;
  }

  body.printing-report-preview .modal-backdrop {
    background: #ffffff !important;
    display: block !important;
    inset: auto;
    padding: 0;
    position: static;
  }

  body.printing-report-preview .modal-backdrop:not(#report-preview-modal) {
    display: none !important;
  }

  body.printing-report-preview .report-preview-modal,
  body.printing-report-preview .report-preview-content,
  body.printing-report-preview .preview-document {
    border: 0;
    box-shadow: none;
    max-height: none;
    max-width: none;
    overflow: visible;
    padding: 0;
  }

  body.printing-report-preview .report-preview-content {
    background: #ffffff;
  }

  body.printing-report-preview .preview-chart-grid img {
    max-height: 210px;
  }
}
