:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef2ea;
  --line: #dfe5dc;
  --text: #18201a;
  --muted: #667063;
  --green: #167246;
  --green-soft: #dceee4;
  --red: #b43d3d;
  --red-soft: #f4dedb;
  --gold: #a96d1f;
  --sheet-blue: #cfe2f3;
  --sheet-header: #6fa8dc;
  --sheet-pink: #f4cccc;
  --sheet-yellow: #fff2cc;
  --sheet-gray: #efefef;
  --ink: #26312a;
  --shadow: 0 18px 50px rgba(35, 47, 38, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(22, 114, 70, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(169, 109, 31, 0.1), transparent 32%),
    var(--bg);
  color: var(--text);
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  overflow: auto;
  background: #edf1ec;
  padding: 24px;
}

.access-panel {
  width: min(100%, 440px);
  display: grid;
  gap: 22px;
  border: 1px solid #d6ddd4;
  border-top: 6px solid #1d2a22;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(35, 47, 38, 0.14);
  padding: 30px;
}

.access-brand {
  width: 58px;
  height: 58px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  border: 1px solid #dce3da;
  border-radius: 8px;
  background: #f5faf1;
  padding: 10px;
}

.access-brand span {
  border-radius: 4px;
  background: var(--green);
}

.access-brand span:nth-child(2) {
  background: var(--gold);
}

.access-brand span:nth-child(3) {
  background: #79907e;
}

.access-eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 14px;
  font-weight: 900;
}

.access-panel h1 {
  margin: 0;
  font-size: clamp(26px, 7vw, 34px);
  line-height: 1.25;
  letter-spacing: 0;
}

.access-description,
.access-note {
  color: var(--muted);
}

.access-description {
  margin: 10px 0 0;
  line-height: 1.6;
}

.access-form {
  display: grid;
  gap: 16px;
}

.access-form label {
  display: grid;
  gap: 8px;
  font-weight: 800;
}

.access-form input {
  width: 100%;
  min-height: 58px;
  border: 1px solid #cfd8cc;
  border-radius: 8px;
  background: #fff;
  padding: 0 16px;
  font-size: 22px;
  letter-spacing: 0;
}

.access-form input:focus {
  border-color: var(--green);
  outline: 3px solid rgba(22, 114, 70, 0.14);
}

.access-submit {
  min-height: 56px;
  justify-content: center;
  font-size: 18px;
}

.access-error {
  min-height: 22px;
  color: var(--red);
  font-weight: 800;
}

.access-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

.access-pending .app-shell,
.access-locked .app-shell {
  visibility: hidden;
}

.access-granted .access-gate,
.access-local .access-gate {
  display: none;
}

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

button {
  cursor: pointer;
}

@media (max-width: 600px) {
  .access-gate {
    align-items: start;
    padding: 16px;
  }

  .access-panel {
    margin-top: 7vh;
    padding: 24px 20px;
  }
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #1d2a22;
  color: #f7fbf4;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.server-status {
  min-height: 50px;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  padding: 8px 12px;
}

.server-status > span:last-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.server-status strong,
.server-status small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-status strong {
  font-size: 13px;
}

.server-status small {
  color: rgba(247, 251, 244, 0.68);
  font-size: 11px;
}

.server-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a7b1aa;
}

.server-status.online .server-status-dot {
  background: #5ee59b;
}

.server-status.syncing .server-status-dot {
  background: #f4c767;
}

.server-status.error .server-status-dot {
  background: #ff8c82;
}

.sidebar-settings-button,
.sidebar-back-button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 0 14px;
  text-align: left;
  font-weight: 800;
}

.admin-menu-button {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #f5faf1;
  color: #132016;
  padding: 0 14px;
  text-align: left;
  font-weight: 900;
}

.admin-menu-button span:last-child {
  font-size: 22px;
}

.admin-nav {
  display: none;
  gap: 8px;
}

.admin-menu-open .admin-nav {
  display: grid;
}

.sidebar-back-button {
  display: none;
  background: #f5faf1;
  color: #132016;
  text-align: left;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #f5faf1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
}

.brand-mark span {
  border-radius: 3px;
  background: var(--green);
}

.brand-mark span:nth-child(2) {
  background: var(--gold);
}

.brand-mark span:nth-child(3) {
  background: #6d8574;
}

.brand p,
.panel-heading p,
.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.brand p,
.sidebar .section-title {
  color: rgba(247, 251, 244, 0.72);
}

.brand h1,
.topbar h2,
.panel-heading h3 {
  margin: 2px 0 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 22px;
}

.business-panel {
  display: grid;
  gap: 12px;
}

.tag-settings-list {
  display: grid;
  gap: 8px;
}

.tag-setting-row {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 48px auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
}

.tag-setting-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-swatch {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 6px;
}

.tag-setting-row input[type="color"],
.tag-add-form input[type="color"] {
  width: 42px;
  min-height: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  padding: 2px;
}

.tag-delete-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--red);
  padding: 0 9px;
  font-weight: 800;
}

.tag-add-form {
  display: grid;
  gap: 14px;
}

.tag-add-form input[type="text"] {
  min-height: 44px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}

.business-list {
  display: grid;
  gap: 8px;
}

.business-row {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: stretch;
}

.business-row.active {
  background: #f5faf1;
  color: #132016;
}

.business-item {
  min-width: 0;
  border: 0;
  border-radius: 8px 0 0 8px;
  background: transparent;
  color: currentColor;
  padding: 12px;
  text-align: left;
  display: grid;
  gap: 4px;
}

.business-item span {
  font-size: 12px;
  color: currentColor;
  opacity: 0.72;
}

.business-edit-button {
  width: 38px;
  border: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0 8px 8px 0;
  background: rgba(255, 255, 255, 0.06);
  color: currentColor;
  font-size: 17px;
}

.business-row.active .business-edit-button {
  border-left-color: rgba(19, 32, 22, 0.12);
  background: rgba(19, 32, 22, 0.06);
}

.main-content {
  min-width: 0;
  padding: 24px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar,
.panel-heading,
.ledger-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  font-size: 30px;
}

.top-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions {
  display: none;
  justify-content: flex-end;
}

.admin-menu-open .top-actions {
  display: flex;
}

.settings-corner-button {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 30;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid rgba(29, 42, 34, 0.16);
  background: #fff;
  color: var(--text);
  padding: 0 14px;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}

.settings-mode .sidebar-settings-button,
.dashboard-mode .sidebar-settings-button,
.health-mode .sidebar-settings-button,
.archive-mode .sidebar-settings-button,
.history-mode .sidebar-settings-button,
.print-preview-mode .sidebar-settings-button {
  display: none;
}

.settings-mode .admin-menu-button,
.settings-mode .admin-nav,
.dashboard-mode .admin-menu-button,
.dashboard-mode .admin-nav,
.health-mode .admin-menu-button,
.health-mode .admin-nav,
.archive-mode .admin-menu-button,
.archive-mode .admin-nav,
.history-mode .admin-menu-button,
.history-mode .admin-nav {
  display: none;
}

.settings-mode .business-panel,
.dashboard-mode .business-panel,
.health-mode .business-panel,
.archive-mode .business-panel,
.history-mode .business-panel {
  display: none;
}

.settings-mode #backToLedgerButton,
.dashboard-mode #backFromDashboardButton,
.health-mode #backFromHealthButton,
.archive-mode #backFromArchiveButton,
.history-mode #backFromHistoryButton {
  display: block;
}

.settings-mode #backFromArchiveButton,
.settings-mode #backFromDashboardButton,
.settings-mode #backFromHealthButton,
.settings-mode #backFromHistoryButton,
.dashboard-mode #backToLedgerButton,
.dashboard-mode #backFromArchiveButton,
.dashboard-mode #backFromHealthButton,
.dashboard-mode #backFromHistoryButton,
.health-mode #backToLedgerButton,
.health-mode #backFromDashboardButton,
.health-mode #backFromArchiveButton,
.health-mode #backFromHistoryButton,
.archive-mode #backToLedgerButton,
.archive-mode #backFromDashboardButton,
.archive-mode #backFromHealthButton,
.archive-mode #backFromHistoryButton,
.history-mode #backToLedgerButton,
.history-mode #backFromDashboardButton,
.history-mode #backFromHealthButton,
.history-mode #backFromArchiveButton {
  display: none;
}

.primary-button,
.ghost-button,
.text-button,
.submit-button,
.danger-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.primary-button,
.submit-button {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.danger-button {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  margin-right: auto;
}

.danger-outline {
  border-color: rgba(180, 61, 61, 0.35);
  background: var(--red-soft);
  color: var(--red);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0;
}

.period-bar {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.period-bar label {
  min-width: 220px;
}

.period-actions {
  display: none;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-menu-open .period-actions {
  display: flex;
}

.period-status {
  display: inline-flex;
  width: fit-content;
  min-height: 34px;
  align-items: center;
  border: 1px solid rgba(22, 114, 70, 0.2);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  padding: 6px 12px;
  font-weight: 800;
}

.period-status.closed {
  border-color: rgba(31, 58, 95, 0.24);
  background: #e6edf5;
  color: #1f3a5f;
}

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

.summary-strip article,
.entry-panel,
.ledger-panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-strip article {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 13px;
}

.summary-strip strong {
  font-size: 24px;
}

.income {
  color: var(--green);
}

.expense {
  color: var(--red);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.entry-panel,
.ledger-panel,
.table-wrap {
  min-width: 0;
}

.entry-panel {
  max-width: none;
}

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

.entry-form .form-wide,
.entry-form .submit-button {
  grid-column: 1 / -1;
}

.entry-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.undo-entry-button {
  max-width: min(100%, 360px);
  min-height: 40px;
  border: 1px solid rgba(169, 109, 31, 0.3);
  border-radius: 8px;
  background: #fff8e8;
  color: #78501d;
  padding: 6px 12px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#addBusinessButton,
.business-edit-button {
  display: none;
}

.admin-menu-open #addBusinessButton {
  display: grid;
}

.admin-menu-open .business-edit-button {
  display: block;
}

.settings-page,
.dashboard-page,
.health-page,
.archive-page,
.history-page {
  display: none;
}

.settings-mode .summary-strip,
.settings-mode .period-bar,
.settings-mode .period-status,
.settings-mode .workspace,
.dashboard-mode .topbar,
.dashboard-mode .summary-strip,
.dashboard-mode .period-bar,
.dashboard-mode .period-status,
.dashboard-mode .workspace,
.health-mode .topbar,
.health-mode .summary-strip,
.health-mode .period-bar,
.health-mode .period-status,
.health-mode .workspace,
.archive-mode .topbar,
.archive-mode .summary-strip,
.archive-mode .period-bar,
.archive-mode .period-status,
.archive-mode .workspace,
.history-mode .topbar,
.history-mode .summary-strip,
.history-mode .period-bar,
.history-mode .period-status,
.history-mode .workspace {
  display: none;
}

.settings-mode .settings-page {
  display: grid;
  gap: 18px;
}

.dashboard-mode .dashboard-page {
  display: grid;
  gap: 18px;
}

.health-mode .health-page {
  display: grid;
  gap: 18px;
}

.archive-mode .archive-page {
  display: grid;
  gap: 18px;
}

.history-mode .history-page {
  display: grid;
  gap: 18px;
}

.archive-mode .archive-summary {
  display: grid;
}

.dashboard-mode .dashboard-summary {
  display: grid;
}

.health-mode .health-summary {
  display: grid;
}

.settings-header,
.settings-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-header {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.settings-header p,
.settings-card-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-header h3,
.settings-card-heading h4 {
  margin: 3px 0 0;
  letter-spacing: 0;
}

.settings-header h3 {
  font-size: 28px;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.settings-card {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 16px;
}

.quick-settings-card {
  grid-column: 1 / -1;
}

.admin-security-card {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.admin-security-card .settings-card-heading {
  grid-column: 1 / -1;
}

.admin-pin-status {
  display: grid;
  gap: 3px;
}

.admin-pin-status span {
  color: var(--muted);
  font-size: 13px;
}

.admin-pin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-pin-actions .danger-button {
  margin-right: 0;
}

.quick-settings-list {
  display: grid;
  gap: 8px;
}

.quick-setting-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 180px) auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.quick-setting-row:last-child {
  border-bottom: 0;
}

.quick-setting-actions {
  display: grid;
  grid-template-columns: 38px 38px auto auto;
  gap: 6px;
}

.quick-setting-actions button {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
}

.quick-setting-actions .quick-delete-button {
  color: var(--red);
  padding: 0 10px;
}

.quick-setting-actions .quick-save-button {
  color: var(--green);
  padding: 0 10px;
}

.quick-add-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 180px) auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.archive-controls,
.dashboard-controls,
.history-controls {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(200px, 260px) auto;
  gap: 14px;
  align-items: end;
}

.history-controls {
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) minmax(180px, 240px);
}

.dashboard-controls {
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) minmax(160px, 220px);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

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

.dashboard-card,
.health-card,
.backup-status-list {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dashboard-card {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.health-card {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.health-card-wide {
  grid-column: 1 / -1;
}

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

.dashboard-card-wide {
  grid-column: 1 / -1;
}

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

.report-list,
.health-list,
.backup-status-list {
  display: grid;
  gap: 10px;
}

.health-row {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.health-row span {
  color: var(--muted);
  font-size: 13px;
}

.health-row.ok {
  border-left: 5px solid var(--green);
}

.health-row.warn {
  border-left: 5px solid var(--gold);
}

.health-row.danger {
  border-left: 5px solid var(--red);
}

.backup-status-list {
  padding: 12px;
  box-shadow: none;
}

.backup-status-row {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.backup-status-row span,
.report-row-main span {
  color: var(--muted);
  font-size: 13px;
}

.system-backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  min-width: 0;
}

.report-row-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.report-row-main strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.report-bar {
  height: 12px;
  border-radius: 999px;
  background: #e6edf5;
  overflow: hidden;
}

.report-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.report-row-money {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  justify-content: stretch;
  text-align: right;
  min-width: 0;
}

.report-row-money span,
.report-row-money strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.report-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.top-expense-list {
  display: grid;
  gap: 8px;
}

.top-expense-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) minmax(130px, auto) auto;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.top-expense-row:last-child {
  border-bottom: 0;
}

.expense-rank {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e6edf5;
  color: #1f3a5f;
  font-weight: 900;
}

.top-expense-row > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.top-expense-row small {
  color: var(--muted);
}

.archive-ledger {
  padding: 18px;
}

.archive-ledger table {
  min-width: 860px;
}

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

.history-item {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.history-item strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
}

.history-item p {
  margin: 4px 0 0;
  color: var(--muted);
}

.history-item time {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.history-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid rgba(31, 58, 95, 0.2);
  border-radius: 8px;
  background: #e6edf5;
  color: #1f3a5f;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 900;
}

.entry-panel,
.ledger-panel {
  padding: 18px;
}

.entry-form {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: var(--surface-soft);
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}

.segmented input:checked + label {
  background: #fff;
  color: var(--text);
  box-shadow: 0 6px 18px rgba(33, 45, 37, 0.1);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.amount-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.quick-entry {
  display: grid;
  gap: 8px;
}

.quick-entry > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.quick-entry-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.quick-entry-buttons button {
  min-height: 48px;
  border: 1px solid #cbd7ca;
  border-radius: 8px;
  background: #f5faf1;
  color: var(--text);
  padding: 8px;
  font-weight: 900;
}

.quick-entry-buttons button:active {
  background: var(--green-soft);
}

.advanced-entry-toggle {
  min-height: 42px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: #1f3a5f;
  text-align: left;
  padding: 10px 0 0;
  font-weight: 900;
}

.advanced-entry-fields {
  display: none;
  gap: 14px;
}

.advanced-entry-open .advanced-entry-fields {
  display: grid;
}

.entry-form .submit-button {
  min-height: 56px;
  font-size: 18px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 120px minmax(132px, 150px) minmax(132px, 150px);
  gap: 8px;
  width: min(100%, 660px);
}

.report-title {
  border: 1px solid #1f3a5f;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #1f3a5f;
  color: #fff;
  padding: 12px 14px;
  text-align: center;
  font-size: 22px;
  font-weight: 900;
}

.ledger-panel .panel-heading {
  border-left: 1px solid #334155;
  border-right: 1px solid #334155;
  background: #f8fafc;
  padding: 14px;
  margin: 0;
  align-items: flex-start;
  flex-wrap: wrap;
}

.table-wrap {
  margin-top: 16px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1040px;
  table-layout: fixed;
  border: 1px solid #334155;
}

th,
td {
  padding: 9px 9px;
  border: 1px solid #334155;
  text-align: left;
  vertical-align: top;
  line-height: 1.25;
}

th {
  color: #111827;
  font-size: 16px;
  font-weight: 800;
  background: #e5e7eb;
}

td.amount,
th:nth-child(4),
th:nth-child(5),
th:nth-child(6) {
  text-align: right;
  white-space: nowrap;
}

th:nth-child(1),
td:nth-child(1) {
  background: #e6edf5 !important;
  text-align: center;
  width: 72px;
  white-space: nowrap;
}

th:nth-child(2),
td:nth-child(2) {
  background: #e6edf5 !important;
  text-align: center;
  width: 132px;
  white-space: nowrap;
}

th:nth-child(3),
td:nth-child(3) {
  width: auto;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6) {
  width: 148px;
}

th:nth-child(7),
td:nth-child(7) {
  width: 108px;
}

th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6) {
  background: #fff;
}

tbody tr:nth-child(even) td {
  background: #eef3f8 !important;
}

tbody tr:nth-child(even) td:nth-child(1),
tbody tr:nth-child(even) td:nth-child(2) {
  background: #d8e3ef !important;
}

.row-title {
  display: grid;
  gap: 3px;
}

.row-title small {
  display: none;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.small-button {
  min-width: 38px;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.locked-label {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(31, 58, 95, 0.22);
  border-radius: 8px;
  background: #e6edf5;
  color: #1f3a5f;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.tag-pill {
  min-width: 88px;
  min-height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 14px;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  background: var(--tag-bg, #e5e7eb);
  border: 1px solid var(--tag-border, #94a3b8);
  color: var(--tag-text, #111827);
}

.tag-kt {
  background: #137a4b;
  color: #d9f2ce;
}

.tag-ry {
  background: #5b3188;
  color: #eadbf9;
}

.tag-other {
  background: #f8c7c0;
  color: #b10000;
}

.tag-none {
  background: #e5e7eb;
  color: #111827;
}

.print-day {
  display: inline;
}

.screen-date {
  display: none;
}

.delete-button {
  color: var(--red);
}

.preview-exit {
  display: none;
}

.mobile-ledger {
  display: none;
}

.ledger-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.ledger-card header,
.ledger-card .money-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ledger-card h4 {
  margin: 0;
  font-size: 16px;
}

.ledger-card small,
.ledger-card span {
  color: var(--muted);
}

.empty-state {
  display: none;
  margin-top: 18px;
  padding: 30px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: var(--text);
  margin-bottom: 5px;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
  width: min(92vw, 420px);
}

dialog::backdrop {
  background: rgba(19, 26, 22, 0.38);
}

dialog form {
  padding: 20px;
  display: grid;
  gap: 16px;
}

dialog h3 {
  margin: 0;
}

.undo-dialog {
  width: min(92vw, 460px);
}

.undo-dialog-content {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.undo-dialog-content p,
.undo-dialog-content h3 {
  margin: 0;
}

.undo-dialog-content p {
  color: var(--muted);
  font-size: 13px;
}

.undo-entry-summary {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.undo-entry-summary span {
  color: var(--muted);
}

.undo-entry-summary b {
  font-size: 22px;
}

.undo-dialog .dialog-actions {
  justify-content: flex-end;
}

.undo-dialog .danger-button {
  margin-right: 0;
}

.pin-dialog {
  width: min(92vw, 430px);
}

.pin-dialog-description {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.pin-dialog form > div:first-child p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.pin-dialog input {
  font-size: 22px;
  letter-spacing: 0;
  text-align: center;
}

.pin-error {
  min-height: 22px;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

.server-conflict-dialog {
  width: min(92vw, 560px);
}

.server-conflict-content {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.server-conflict-content p,
.server-conflict-content h3 {
  margin: 0;
}

.server-conflict-content > p {
  color: var(--muted);
  line-height: 1.6;
}

.server-conflict-content > div:first-child p {
  color: var(--muted);
  font-size: 13px;
}

.server-conflict-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.save-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 80;
  width: min(calc(100vw - 28px), 560px);
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid rgba(22, 114, 70, 0.3);
  border-radius: 8px;
  background: #f3fbf6;
  color: var(--text);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.2);
  padding: 14px 16px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 18px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.save-toast > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.save-toast strong,
.save-toast span {
  overflow-wrap: anywhere;
}

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

.save-toast button {
  min-width: 44px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    z-index: 5;
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr;
  }

  .business-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, 1fr);
    overflow-x: auto;
    padding-bottom: 2px;
  }

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

@media (min-width: 1081px) and (max-width: 1360px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .main-content {
    padding: 14px;
  }

  .topbar,
  .panel-heading,
  .ledger-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .entry-heading-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .undo-entry-button {
    max-width: none;
    width: 100%;
  }

  .topbar h2 {
    font-size: 24px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .settings-corner-button {
    top: 12px;
    right: 12px;
    min-height: 38px;
    padding: 0 11px;
    font-size: 13px;
  }

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

  .summary-strip strong {
    font-size: 20px;
  }

  .form-grid,
  .filters,
  .entry-form,
  .amount-grid,
  .quick-add-form,
  .quick-setting-row,
  .archive-controls,
  .dashboard-controls,
  .history-controls {
    grid-template-columns: 1fr;
  }

  .quick-setting-actions {
    grid-template-columns: 44px 44px minmax(72px, auto) minmax(64px, auto);
    justify-content: end;
  }

  .quick-entry-buttons {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-grid,
  .health-grid,
  .report-row-money {
    grid-template-columns: 1fr;
  }

  .health-summary,
  .dashboard-summary {
    grid-template-columns: 1fr 1fr;
  }

  .report-row-money {
    text-align: left;
  }

  .top-expense-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

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

  .period-bar label {
    min-width: 0;
  }

  .period-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

  .admin-security-card {
    grid-template-columns: 1fr;
  }

  .admin-pin-actions {
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .server-conflict-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .settings-header {
    align-items: stretch;
    flex-direction: column;
  }

  .table-wrap {
    display: none;
  }

  .archive-mode .archive-ledger .table-wrap {
    display: block;
  }

  .mobile-ledger {
    display: grid;
    gap: 10px;
    margin-top: 16px;
  }
}

@media (max-width: 430px) {
  .sidebar {
    padding: 12px;
  }

  .brand h1 {
    font-size: 19px;
  }

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

  .top-actions {
    grid-template-columns: 1fr;
  }
}

.print-preview-mode {
  background: #dfe3e8;
}

.print-preview-mode .app-shell,
.print-preview-mode .main-content,
.print-preview-mode .workspace {
  display: block;
  min-height: auto;
}

.print-preview-mode .main-content {
  width: max-content;
  min-width: 1120px;
  margin: 0 auto;
  padding: 28px;
}

.print-preview-mode .sidebar,
.print-preview-mode .topbar,
.print-preview-mode .period-bar,
.print-preview-mode .period-status,
.print-preview-mode .summary-strip,
.print-preview-mode .entry-panel,
.print-preview-mode .settings-page,
.print-preview-mode .dashboard-page,
.print-preview-mode .health-page,
.print-preview-mode .archive-page,
.print-preview-mode .history-page,
.print-preview-mode .ledger-heading,
.print-preview-mode .mobile-ledger,
.print-preview-mode .empty-state,
.print-preview-mode .row-actions,
.print-preview-mode th:last-child,
.print-preview-mode td:last-child {
  display: none !important;
}

.print-preview-mode .ledger-panel {
  background: #fff;
  border: 0;
  border-radius: 2px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
  width: 1060px;
  min-height: 720px;
  padding: 34px;
}

.print-preview-mode .report-title {
  background: #1f3a5f;
  border: 1px solid #1f3a5f;
  border-radius: 0;
  color: #fff;
  font-size: 21px;
  letter-spacing: 0;
  padding: 12px 14px;
}

.print-preview-mode .table-wrap {
  display: block !important;
  overflow: visible;
  margin-top: 0;
}

.print-preview-mode table {
  min-width: 0;
  table-layout: fixed;
  border: 1px solid #334155;
}

.print-preview-mode th,
.print-preview-mode td {
  border: 1px solid #334155;
  padding: 8px 9px;
  font-size: 14px;
  line-height: 1.25;
}

.print-preview-mode th {
  background: #e5e7eb;
  color: #111827;
  font-size: 15px;
  font-weight: 800;
}

.print-preview-mode td {
  background: #fff !important;
  color: #111827;
}

.print-preview-mode tbody tr:nth-child(even) td {
  background: #eef3f8 !important;
}

.print-preview-mode tbody tr td {
  border-bottom-width: 1.5px;
}

.print-preview-mode td:nth-child(1),
.print-preview-mode td:nth-child(2) {
  background: #e6edf5 !important;
}

.print-preview-mode tbody tr:nth-child(even) td:nth-child(1),
.print-preview-mode tbody tr:nth-child(even) td:nth-child(2) {
  background: #d8e3ef !important;
}

.print-preview-mode th:nth-child(1),
.print-preview-mode th:nth-child(2),
.print-preview-mode th:nth-child(3),
.print-preview-mode th:nth-child(4),
.print-preview-mode th:nth-child(5),
.print-preview-mode th:nth-child(6) {
  background: #e5e7eb;
}

.print-preview-mode .tag-pill {
  min-width: 48px;
  min-height: 22px;
  border-radius: 4px;
  border: 1px solid var(--tag-border, #94a3b8);
  background: var(--tag-bg, #f8fafc) !important;
  color: var(--tag-text, #111827) !important;
  font-size: 13px;
  padding: 2px 6px;
}

.print-preview-mode .row-title small {
  display: none;
}

.print-preview-mode .screen-date {
  display: none;
}

.print-preview-mode .print-day {
  display: inline;
}

.print-preview-mode th:nth-child(1),
.print-preview-mode td:nth-child(1) {
  width: 5%;
}

.print-preview-mode th:nth-child(2),
.print-preview-mode td:nth-child(2) {
  width: 7%;
}

.print-preview-mode th:nth-child(3),
.print-preview-mode td:nth-child(3) {
  width: 52%;
}

.print-preview-mode th:nth-child(4),
.print-preview-mode td:nth-child(4),
.print-preview-mode th:nth-child(5),
.print-preview-mode td:nth-child(5),
.print-preview-mode th:nth-child(6),
.print-preview-mode td:nth-child(6) {
  width: 12%;
}

.print-preview-mode .preview-exit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  padding: 0 18px;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

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

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    background: #fff;
  }

  .app-shell,
  .main-content,
  .workspace {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .sidebar,
  .topbar,
  .period-bar,
  .period-status,
  .summary-strip,
  .entry-panel,
  .settings-page,
  .dashboard-page,
  .health-page,
  .archive-page,
  .history-page,
  .ledger-heading,
  .mobile-ledger,
  .empty-state,
  .row-actions,
  th:last-child,
  td:last-child {
    display: none !important;
  }

  .ledger-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    background: #fff;
  }

  .report-title {
    background: #1f3a5f;
    border: 1px solid #1f3a5f;
    border-radius: 0;
    color: #fff;
    font-size: 19px;
    padding: 10px 12px;
  }

  .table-wrap {
    display: block !important;
    overflow: visible;
    margin-top: 0;
  }

  table {
    border: 1px solid #334155;
    min-width: 0;
    width: 100%;
    table-layout: fixed;
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  th,
  td {
    border: 1px solid #334155;
    padding: 7px 8px;
    font-size: 13px;
    line-height: 1.25;
  }

  th {
    background: #e5e7eb !important;
    color: #111827;
    font-size: 14px;
  }

  td {
    background: #fff !important;
    color: #111827;
  }

  tbody tr:nth-child(even) td {
    background: #eef3f8 !important;
  }

  tbody tr td {
    border-bottom-width: 1.5px;
  }

  td:nth-child(1),
  td:nth-child(2) {
    background: #e6edf5 !important;
  }

  tbody tr:nth-child(even) td:nth-child(1),
  tbody tr:nth-child(even) td:nth-child(2) {
    background: #d8e3ef !important;
  }

  th:nth-child(1),
  td:nth-child(1) {
    width: 5%;
  }

  th:nth-child(2),
  td:nth-child(2) {
    width: 7%;
  }

  th:nth-child(3),
  td:nth-child(3) {
    width: 52%;
  }

  th:nth-child(4),
  td:nth-child(4),
  th:nth-child(5),
  td:nth-child(5),
  th:nth-child(6),
  td:nth-child(6) {
    width: 12%;
  }

  .row-title small {
    display: none;
  }

  .tag-pill {
    min-width: 48px;
    min-height: 22px;
    border-radius: 4px;
    border: 1px solid var(--tag-border, #94a3b8);
    background: var(--tag-bg, #f8fafc) !important;
    color: var(--tag-text, #111827) !important;
    font-size: 13px;
    padding: 2px 6px;
  }

  .screen-date {
    display: none;
  }

  .print-day {
    display: inline;
  }

  .report-print-mode .dashboard-page {
    display: grid !important;
    gap: 10px;
  }

  .report-print-mode .dashboard-controls,
  .report-print-mode #printDashboardButton,
  .report-print-mode .ledger-panel {
    display: none !important;
  }

  .report-print-mode .dashboard-summary {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .report-print-mode .dashboard-grid {
    gap: 10px;
  }

  .report-print-mode .dashboard-card,
  .report-print-mode .summary-strip {
    box-shadow: none;
    break-inside: avoid;
  }

  .report-print-mode .report-row {
    padding: 8px 10px;
    gap: 6px;
  }
}
