@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: local('Inter'), local('Inter-Regular'), local('Segoe UI'), local('Roboto'), local('Helvetica Neue'), local('Arial');
}
/* TK-01..TK-35: Pixel-measured Monarch Design Tokens (1920x1440 reference) */
:root {
  --bg-page: #F7F5F4;
  --bg-sidebar: #F7F5F4;
  --bg-sidebar-hover: #EFECE8;
  --bg-sidebar-active: #ECEAE6;
  --bg-card: #FFFFFF;
  --text-main: #1E1F1C;
  --text-muted: #74726F;
  --text-tab-inactive: #6F6D6B;
  --border-col: #E4E2DE;
  --row-divider: #F0EEEB;
  --monarch-orange: #FF6B2C;
  --monarch-orange-btn: #C2410C;
  --monarch-orange-hover: #9A3412;
  --monarch-green: #15803D;
  --monarch-green-tint: #E8F5EE;
  --monarch-red: #DC2626;
  --monarch-pink-bar: #F6C7C7;
  --monarch-mint-bar: #D6F0E0;
  --monarch-link: #1B87A5;
  --monarch-teal-pill: #E0F4F8;
  --monarch-blue: #2563EB;
  --card-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
html.dark {
  --monarch-orange-btn: #C2410C;
  --monarch-orange-hover: #9A3412;
  --bg-page: #111116;
  --bg-sidebar: #111116;
  --bg-sidebar-hover: #1C1C26;
  --bg-sidebar-active: #252533;
  --bg-card: #1A1A24;
  --text-main: #F3F4F6;
  --text-muted: #A1A1AA;
  --text-tab-inactive: #9CA3AF;
  --border-col: #2E2E3E;
  --row-divider: #252533;
  --monarch-green: #4ADE80;
  --monarch-green-tint: #0F291E;
  --monarch-pink-bar: #3B1820;
  --monarch-mint-bar: #0F291E;
  --monarch-link: #38BDF8;
  --monarch-teal-pill: #0C2D3A;
  --card-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; width: 100%; }
body {
  min-height: 100vh;
  width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { cursor: pointer; background: none; border: none; }
a { color: var(--monarch-link); text-decoration: none; }
.link-teal {
  color: var(--monarch-link);
  font-weight: 500;
  cursor: pointer;
}
.link-teal:hover { text-decoration: underline; }

/* Accessible Focus Ring (AX-03) */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--monarch-orange) !important;
  outline-offset: 2px !important;
}

/* App Shell & Light Sidebar (TK-13, TK-14, TK-21..TK-25) */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-page);
}
.sidebar {
  width: 228px;
  min-width: 228px;
  background: var(--bg-sidebar);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  border-right: none;
  transition: width 0.18s ease, min-width 0.18s ease, transform 0.2s ease;
  z-index: 40;
  user-select: none;
}
.sidebar.collapsed {
  width: 60px;
  min-width: 60px;
}
.sidebar.collapsed .hide-collapsed { display: none !important; }
.sidebar-top-bar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}
.sidebar-top-icons {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  position: relative;
  transition: background 0.12s;
}
.sidebar-icon-btn:hover {
  background: var(--bg-sidebar-hover);
}
.nav-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 0px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 38px;
  width: 212px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--text-main);
  font-weight: 500;
  font-size: 15px;
  transition: background 0.12s;
  text-align: left;
}
.sidebar.collapsed .nav-item {
  width: 44px;
  justify-content: center;
  padding: 0;
}
.nav-item:hover {
  background: var(--bg-sidebar-hover);
}
.nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-main);
  font-weight: 600;
}
/* TK-35: Recurring count orange rounded square 20x20px, radius 6px */
.nav-badge {
  margin-left: auto;
  background: var(--monarch-orange-btn);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 600;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-footer {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* TK-25: White Free trial card with progress bar */
.trial-card {
  background: var(--bg-card);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  padding: 12px 14px;
  margin: 0 4px 8px;
  font-size: 13px;
  color: var(--text-main);
}

/* Main Workspace &#x2014; Content starts at x=240px, first card at y=64px (TK-21, TK-26, TK-27) */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-page);
}
.page-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 16px 56px 12px;
}
/* Single 64px Header Row on Page Background (TK-02, TK-26, TK-27) */
.page-header-row {
  height: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: transparent;
}
.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0;
  white-space: nowrap;
}
/* Header Text Tabs with 3px Orange Underline (TK-10) */
.header-tabs {
  display: inline-flex;
  align-items: center;
  gap: 22px;
  height: 64px;
}
.header-tab {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-tab-inactive);
  height: 100%;
  display: inline-flex;
  align-items: center;
  border-bottom: 3px solid transparent;
  padding: 0 2px;
  transition: color 0.12s, border-color 0.12s;
}
.header-tab:hover { color: var(--text-main); }
.header-tab.active {
  color: var(--monarch-orange);
  border-bottom-color: var(--monarch-orange);
  font-weight: 600;
}

/* Cards & Grid (TK-04, TK-05, TK-28, TK-29, TK-30) */
.m-card {
  background: var(--bg-card);
  border: none;
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  padding: 18px 20px;
  min-width: 0;
}
.m-card.flush { padding: 0; }
.m-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.m-card.flush .m-card-header {
  padding: 18px 20px 12px;
  margin-bottom: 0;
}
.m-card-title-link {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-size: 18px;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
}
.m-card-title-link:hover .title-main {
  color: var(--monarch-orange);
}
.m-card-sub {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-muted);
}
/* Two equal columns with 16px gutter (TK-29) */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.dash-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Split layout with right 320px summary rail (ACC-04, TRA-06) */
.split-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.split-page.with-rail {
  grid-template-columns: minmax(0, 1fr) 320px;
}
.settings-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.kpi-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

/* Buttons, Inputs, Selects & Labels (TK-11, TK-31, TK-32, TK-33) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  border: 1px solid var(--border-col);
  background: var(--bg-card);
  color: var(--text-main);
  transition: all 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-sidebar-hover); }
.btn-primary {
  background: var(--monarch-orange-btn);
  border-color: var(--monarch-orange-btn);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 14px;
  height: 36px;
  padding: 0 14px;
}
.btn-primary:hover { background: var(--monarch-orange-hover); }
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
}
.btn-ghost:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-main);
}
.select-pill {
  appearance: none;
  background-color: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 8px;
  height: 36px;
  padding: 0 30px 0 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2374726F' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.input-box {
  height: 42px;
  border: 1px solid var(--border-col);
  background: var(--bg-card);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 15px;
  color: var(--text-main);
  width: 100%;
}
textarea.input-box {
  height: auto;
  padding: 10px 12px;
}
.input-box:focus, .select-pill:focus {
  border-color: var(--monarch-orange);
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

/* Segmented Controls */
.seg-tabs {
  display: inline-flex;
  background: #ECEAE6;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
html.dark .seg-tabs { background: #252533; }
.seg-tab {
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}
.seg-tab.active {
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Read-only 50px Transaction Rows (TK-07, TK-09, TRA-03, TRA-05) */
.tx-row {
  display: grid;
  grid-template-columns: minmax(190px, 1.4fr) minmax(170px, 1.15fr) minmax(160px, 1.1fr) minmax(80px, 0.6fr) 120px 28px;
  align-items: center;
  gap: 12px;
  height: 50px;
  padding: 0 20px;
  border-bottom: 1px solid var(--row-divider);
  font-size: 15px;
  color: var(--text-main);
  cursor: pointer;
}
.tx-row.edit-multi {
  grid-template-columns: 28px minmax(180px, 1.4fr) minmax(165px, 1.15fr) minmax(150px, 1.1fr) minmax(70px, 0.6fr) 120px 28px;
}
.tx-row:hover { background: var(--bg-page); }
.date-band {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-page);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--row-divider);
}


/* Anchored Popovers for Search, Date Range, and Filters (TRA-07, TRA-08, TRA-09) */
.popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 31, 28, 0.12);
  z-index: 80;
}
.popover-anchored {
  position: fixed;
  top: 58px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
  max-height: calc(100vh - 76px);
  max-width: calc(100vw - 32px);
  overflow-y: auto;
  z-index: 82;
}

/* Modals (TK-34: radius 12px, 32px padding) & 570px Detail Drawer (TRA-11) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 31, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 20px;
}
.modal-card {
  background: var(--bg-card);
  border: none;
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 45px rgba(0,0,0,0.18);
  overflow-y: auto;
}
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 31, 28, 0.32);
  display: flex;
  justify-content: flex-end;
  z-index: 75;
}
.drawer-panel {
  width: 570px;
  max-width: 95vw;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border-col);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,0.14);
}
/* Floating AI Assistant Panel 450x700px bottom-right (AI -01) */
.ai-floating-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 450px;
  max-width: calc(100vw - 32px);
  height: 700px;
  max-height: calc(100vh - 40px);
  background: var(--bg-card);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.22);
  border: 1px solid var(--border-col);
  display: flex;
  flex-direction: column;
  z-index: 78;
  overflow: hidden;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #D4D2CE;
  transition: .18s;
  border-radius: 999px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .18s;
  border-radius: 50%;
}
input:checked + .slider { background-color: var(--monarch-orange); }
input:checked + .slider:before { transform: translateX(16px); }

/* Badges & Progress Bars */
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.progress-track {
  width: 100%;
  height: 10px;
  background: #ECEAE6;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}
html.dark .progress-track { background: #2E2E3E; }
.progress-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.25s ease;
}
.toast-container {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-item {
  background: #1E1F1C;
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
  display: flex;
  align-items: center;
  gap: 10px;
}
.mobile-menu-btn { display: none; }

/* Responsive Layout under 768px (RS-01) */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 8px 0 24px rgba(0,0,0,0.25);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-col);
    background: var(--bg-card);
  }
  .dash-grid, .split-page.with-rail, .settings-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .kpi-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .tx-row {
    grid-template-columns: minmax(0, 1fr) auto 24px;
    height: auto;
    padding: 10px 14px;
    row-gap: 4px;
  }
  .tx-row .tx-col-cat, .tx-row .tx-col-acc, .tx-row .tx-col-tags {
    grid-column: 1 / 3;
    font-size: 13px;
  }

  /* Option B Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 58px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-col);
    z-index: 65;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
  }
  .page-scroll {
    padding-bottom: 78px !important;
  }
}
