:root {
  --bg: #f6f8fc;
  --panel: #ffffff;
  --panel-elevated: #ffffff;
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-light: #f1f5f9;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --primary-dark: #1e3a8a;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --sidebar-active: #2563eb;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 28px -4px rgba(15, 23, 42, 0.1), 0 4px 10px -2px rgba(15, 23, 42, 0.05);
  --shadow-xl: 0 20px 40px -6px rgba(15, 23, 42, 0.16);
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 9999px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Kanit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", "Thonburi", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

/* ============================================================
   APP SHELL LAYOUT (Desktop & Tablet Landscape)
   ============================================================ */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  transition: grid-template-columns 0.2s ease;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 8px 6px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
  width: 80px;
  height: 80px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  flex-shrink: 0;
  box-shadow: none;
}

.brand-logo img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.25));
}

.brand-text {
  text-align: center;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-text p {
  font-size: 0.76rem;
  margin: 3px 0 0;
  color: var(--sidebar-muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav-item.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ============================================================
   MAIN CONTENT & REFINED TOPBAR
   ============================================================ */
.main {
  padding: 24px 28px;
  min-width: 0;
  width: 100%;
  max-width: 1540px;
  margin: 0 auto;
}

/* Refined Header / Topbar (Modern Native Mobile App Style) */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(226, 232, 240, 0.85);
  border-radius: 18px;
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.05), 0 2px 6px -1px rgba(15, 23, 42, 0.03);
  position: sticky;
  top: 12px;
  z-index: 25;
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
}

.topbar-title-area {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mobile-brand-mini {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: transparent;
  padding: 0;
  flex-shrink: 0;
  overflow: visible;
}

.mobile-brand-mini img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.18));
}

.topbar-text-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.topbar-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.page-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  background: #eff6ff;
  color: #2563eb;
  border: 1px solid #bfdbfe;
  letter-spacing: 0.01em;
}

.topbar-date-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: #64748b;
  font-weight: 500;
}

.date-icon {
  font-size: 0.82rem;
  line-height: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Cloud status indicator */
.cloud-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 127px;
  height: 43px;
  padding: 6px 11px;
  border-radius: 12px;
  font-size: 0.76rem;
  font-weight: 700;
  background: #f8fafc;
  color: #64748b;
  border: 1px solid #e2e8f0;
  transition: all 0.2s ease;
  user-select: none;
  box-sizing: border-box;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}

.cloud-status.online {
  background: #f0fdf4;
  color: #16a34a;
  border-color: #bbf7d0;
}

.cloud-status.online .status-dot {
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
}

.cloud-status.syncing {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}

.cloud-status.syncing .status-dot {
  background: #2563eb;
  animation: pulseDot 1s infinite alternate;
}

.cloud-status.error {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

.cloud-status.error .status-dot {
  background: #dc2626;
}

@keyframes pulseDot {
  from { opacity: 0.4; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.15); }
}

.topbar-account-btn {
  padding: 7px 14px;
  font-size: 0.85rem;
  min-height: 38px;
  border-radius: var(--radius-full);
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: var(--text);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s ease;
}

.topbar-account-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.topbar-account-btn:active {
  transform: scale(0.95);
}

.topbar-add-btn {
  padding: 7px 16px;
  font-size: 0.88rem;
  min-height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.3);
  font-weight: 700;
}

.topbar-add-btn:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  box-shadow: 0 5px 14px rgba(37, 99, 235, 0.4);
}

.topbar-add-btn:active {
  transform: scale(0.95);
}

.mobile-only-btn {
  display: none;
}

/* ============================================================
   BUTTONS & CONTROLS
   ============================================================ */
.btn {
  border: 0;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  min-height: 42px;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.btn-secondary:hover {
  background: #dbeafe;
}

.btn-ghost {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
}

.btn-ghost:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-danger-soft {
  background: rgba(220, 38, 38, 0.1);
  color: #ef4444;
  border: 1px solid rgba(220, 38, 38, 0.2);
}

.btn-danger-soft:hover {
  background: rgba(220, 38, 38, 0.2);
  color: #ffffff;
}

.btn-full {
  width: 100%;
}

.file-label {
  cursor: pointer;
  user-select: none;
}

/* ============================================================
   PAGES & CONTAINERS
   ============================================================ */
.page {
  display: none;
  animation: pageFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.page.active {
  display: block;
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   HERO GRID / STAT CARDS
   ============================================================ */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--panel);
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.stat-card.balance-card::before { background: #3b82f6; }
.stat-card.due-card::before { background: #8b5cf6; }
.stat-card.unpaid-card::before { background: #ef4444; }
.stat-card.receive-card::before { background: #10b981; }

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.stat-card strong {
  display: block;
  font-size: clamp(1.35rem, 2vw, 1.8rem);
  font-weight: 800;
  margin: 6px 0 3px;
  color: var(--text);
  letter-spacing: -0.02em;
  word-break: break-word;
}

.stat-card small {
  color: var(--muted);
  font-size: 0.76rem;
  display: block;
}

/* ============================================================
   PANELS & TWO-COLUMN GRIDS
   ============================================================ */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 22px;
}

#dashboard > div:nth-of-type(2) {
  grid-template-columns: repeat(4, 1fr);
}

#dashboard .grid-2 > article:nth-of-type(1) {
  width: 100%;
  max-width: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  margin-bottom: 22px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-head h3 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text);
}

#dashboard .grid-2 article:first-child .panel-head h3 {
  color: #740142;
}

.panel-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.situation-box {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  line-height: 1.65;
  font-size: 0.92rem;
  border: 1px solid var(--line);
}

.situation-box.danger {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: #991b1b;
}

.situation-box.good {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  color: #166534;
}

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

.compact-item.sortable-ghost {
  opacity: 0.5 !important;
  background-color: #f1f5f9 !important;
  border: 1px dashed #94a3b8 !important;
}

.compact-item.sortable-drag {
  background-color: #ffffff !important;
  border: 1px solid var(--primary) !important;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05) !important;
  opacity: 1 !important;
  cursor: grabbing !important;
}

.compact-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  border: 1px solid var(--line-light);
}

.compact-item strong {
  font-size: 0.85rem;
  line-height: 1.2;
}

.compact-item small {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.amount-danger { color: var(--danger) !important; font-weight: 800; }
.amount-success { color: var(--success) !important; font-weight: 800; }

.mini-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.mini-stats > div {
  background: #f8fafc;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--line-light);
}

.mini-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.mini-stats strong {
  display: block;
  margin-top: 5px;
  font-size: 1.15rem;
  font-weight: 800;
}

/* ============================================================
   FILTERS & FORMS
   ============================================================ */
.filters {
  display: flex;
  gap: 10px;
}

.filters select, .form-grid input, .form-grid select {
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  background: #ffffff;
  color: var(--text);
  width: 100%;
  font-size: 0.92rem;
  min-height: 42px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.filters select:focus, .form-grid input:focus, .form-grid select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ============================================================
   PAYMENT LIST & ROWS
   ============================================================ */
.payment-list {
  display: grid;
  gap: 10px;
}

.payment-row {
  display: grid;
  grid-template-columns: 46px 1.4fr 0.8fr 0.8fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s ease;
}

.payment-row:hover {
  box-shadow: var(--shadow-sm);
  border-color: #cbd5e1;
}

.payment-row.paid {
  opacity: 0.65;
  background: #fafafa;
  border-color: var(--line-light);
}

.payment-row.overdue:not(.paid) {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.check-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 800;
  color: transparent;
  transition: all 0.15s ease;
}

.check-btn:active {
  transform: scale(0.9);
}

.check-btn.done {
  background: var(--success);
  color: #ffffff;
  border-color: var(--success);
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.35);
}

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  background: #eef2ff;
  color: var(--primary);
}

.tag.shared {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid var(--warning-border);
}

.tag.income {
  background: var(--success-soft);
  color: var(--success);
}

.action-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 6px 10px;
  font-weight: 700;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
}

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

.mini-edit-btn, .mini-delete-btn {
  border: 0;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.mini-edit-btn:active, .mini-delete-btn:active {
  transform: scale(0.9);
}

.mini-edit-btn { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.mini-delete-btn { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* ============================================================
   DEBT GRID & CARDS
   ============================================================ */
.debt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.debt-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.debt-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.debt-card.kind-credit_card::before { background: #8b5cf6; }
.debt-card.kind-installment::before { background: #3b82f6; }
.debt-card.kind-loan::before { background: #06b6d4; }
.debt-card.kind-statement::before { background: #f97316; }
.debt-card.kind-shared::before { background: #f59e0b; }
.debt-card.kind-shared_installment::before { background: #10b981; }

.debt-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.debt-card h4 {
  margin: 0 0 3px;
  font-size: 1.05rem;
  font-weight: 800;
}

.debt-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.debt-card .big {
  font-size: 1.65rem;
  font-weight: 800;
  margin: 12px 0 8px;
  letter-spacing: -0.02em;
}

.progress {
  height: 8px;
  background: #f1f5f9;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.debt-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.debt-meta div {
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  border: 1px solid var(--line-light);
}

.debt-meta small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.debt-meta strong {
  font-size: 0.88rem;
  display: block;
  margin-top: 2px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-light);
}

.card-actions > * {
  flex: 1 1 auto;
  min-height: 38px;
}

.edit-btn, .delete-btn, .mode-btn {
  border: 0;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}

.edit-btn { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.delete-btn { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.mode-btn { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* Shared Installment Summary */
.shared-installment-summary {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.shared-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.shared-progress-head strong { color: #15803d; }
.shared-progress-head span { font-weight: 800; color: #334155; }

.shared-progress {
  height: 8px;
  background: #dcfce7;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 10px;
}

.shared-progress span {
  display: block;
  height: 100%;
  background: #22c55e;
  border-radius: var(--radius-full);
}

.shared-installment-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.shared-installment-grid > div {
  background: #ffffff;
  border: 1px solid #dcfce7;
  border-radius: var(--radius-xs);
  padding: 6px 8px;
}

.shared-installment-grid small {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 2px;
}

.shared-installment-grid strong {
  display: block;
  font-size: 0.84rem;
  color: var(--text);
}

/* Loan rounds */
.loan-rounds {
  margin-top: 12px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  border: 1px solid var(--line);
}

.loan-rounds-title {
  font-weight: 800;
  margin-bottom: 6px;
  color: #334155;
  font-size: 0.85rem;
}

.loan-round {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-top: 6px;
}

.loan-round-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.loan-round-head strong { font-size: 0.88rem; }
.loan-round-head small {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
  margin-top: 2px;
}

.loan-installments {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.loan-installment {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  background: #fff7ed;
  border-left: 4px solid #f59e0b;
  font-size: 0.82rem;
}

.loan-installment.is-paid {
  background: #f0fdf4;
  border-left-color: #10b981;
}

.loan-installment small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

/* ============================================================
   TABLES (INCOME & FORECAST)
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 580px;
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.88rem;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

tr:last-child td {
  border-bottom: 0;
}

/* ============================================================
   FLOATING ACTION BUTTON (FAB) FOR MOBILE
   ============================================================ */
.fab {
  display: none;
  position: fixed;
  right: 20px;
  bottom: calc(75px + var(--safe-bottom));
  width: 60px;
  height: 60px;
  min-width: 60px;
  padding: 0;
  border-radius: var(--radius-full);
  border: 0;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4);
  z-index: 35;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-weight: 800;
  font-size: 1.5rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fab:active {
  transform: scale(0.92);
}

.fab-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.fab-label,
#fabAdd > span:nth-of-type(2) {
  display: none;
}

/* ============================================================
   MOBILE BOTTOM NAVIGATION BAR
   ============================================================ */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 40;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
}

.mobile-nav-item {
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #64748b;
  padding: 6px 2px;
  height: 100%;
  transition: all 0.15s ease;
}

.mobile-nav-item:active {
  transform: scale(0.92);
}

.mob-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.mob-text {
  font-size: 0.68rem;
  font-weight: 700;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item.active .mob-icon {
  transform: translateY(-2px);
}

/* ============================================================
   MODALS & BOTTOM SHEETS
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 15, 28, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  animation: modalFadeIn 0.2s ease-out;
}

.modal-backdrop.hidden {
  display: none !important;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: #ffffff;
  width: min(680px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius-xl);
  padding: 22px 24px;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
}

.modal-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.icon-btn {
  border: 0;
  background: #f1f5f9;
  border-radius: var(--radius-md);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text);
  transition: all 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.9);
}

.add-type-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.add-type {
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 10px 4px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 1.05rem;
  transition: all 0.15s ease;
  min-height: 60px;
}

.add-type span {
  font-size: 0.7rem;
  font-weight: 700;
}

.add-type.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

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

.field {
  display: grid;
  gap: 5px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.field small {
  color: var(--muted);
  font-size: 0.74rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  background: #ffffff;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

/* Auth Modal */
.auth-modal {
  width: min(440px, 100%);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-md);
  margin: 14px 0 18px;
}

.auth-tab {
  border: 0;
  background: transparent;
  padding: 9px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-note {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 12px 0 0;
}

.account-card {
  padding: 14px 16px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  margin: 14px 0 18px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
}

.account-card span, .account-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

.account-card strong {
  font-size: 1rem;
  word-break: break-all;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* More Menu Modal */
.more-modal {
  width: min(500px, 100%);
}

.more-menu-grid {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.more-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--text);
  text-align: left;
  width: 100%;
  transition: all 0.15s ease;
  min-height: 54px;
}

.more-item:active {
  transform: scale(0.98);
  background: #f1f5f9;
}

.more-item-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.more-item-info strong {
  display: block;
  font-size: 0.92rem;
  color: var(--text);
}

.more-item-info small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 1px;
}

.more-item.danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.more-item.danger .more-item-info strong {
  color: var(--danger);
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  top: 20px;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 60;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-lg);
  background: #fafafa;
  font-size: 0.92rem;
}

/* ============================================================
   ROTATION PLANNER
   ============================================================ */
.planner-start {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 14px;
  align-items: end;
  margin-bottom: 14px;
}

.planner-hint {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-light);
}

.rotation-summary-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 14px 0 20px;
}

.rotation-summary-grid > div {
  padding: 12px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-light);
}

.rotation-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.rotation-summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
  font-weight: 800;
}

.rotation-summary-grid .cost strong {
  color: var(--danger);
}

.planner-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 18px 0 12px;
}

.planner-toolbar h4 {
  margin: 0;
  font-size: 1rem;
}

.planner-toolbar small {
  color: var(--muted);
}

.rotation-steps {
  display: grid;
  gap: 8px;
}

.rotation-step {
  display: grid;
  grid-template-columns: 38px 1.2fr 0.8fr 0.8fr 0.7fr 38px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.rotation-step .step-no {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.rotation-step .field {
  gap: 3px;
}

.rotation-step .field label {
  font-size: 0.7rem;
  color: var(--muted);
}

.rotation-step input {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
  font-size: 0.88rem;
}

.rotation-step .remove-step {
  border: 0;
  background: #fef2f2;
  color: #b91c1c;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.planner-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

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

.saved-plan {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.saved-plan small {
  color: var(--muted);
}

/* Smart debt dynamic form */
.smart-debt-dynamic {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.smart-debt-dynamic > .field.full,
.smart-debt-dynamic > .debt-form-note {
  grid-column: 1 / -1;
}

.smart-debt-dynamic .field {
  min-width: 0;
}

.debt-form-note {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  color: #475569;
  border: 1px solid #e2e8f0;
  font-size: 0.82rem;
}

.smart-installment-editor {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.smart-installment-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #f8fafc;
  min-width: 0;
}

.smart-installment-row label {
  font-size: 0.78rem;
  color: #64748b;
  min-width: 0;
}

.smart-installment-row input {
  margin-top: 3px;
  width: 100%;
  min-width: 0;
}

/* ============================================================
   TABLET LANDSCAPE OPTIMIZATIONS (แท็บเลตเน้นใช้แนวนอน)
   ============================================================ */
@media (min-width: 769px) and (orientation: landscape), (min-width: 992px) {
  .app-shell {
    grid-template-columns: 230px 1fr;
  }

  .main {
    padding: 22px 28px;
  }

  .topbar {
    padding: 12px 18px;
  }

  .hero-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
  }

  .grid-2 {
    grid-template-columns: 1.15fr 0.85fr;
    gap: 18px;
  }

  .debt-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .mini-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }

  .rotation-summary-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
  }
}

/* Medium Tablets in Landscape (768px - 1080px) */
@media (min-width: 769px) and (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 210px 1fr;
  }

  .main {
    padding: 16px 18px;
  }

  #debts .panel,
  #calendar .panel {
    padding: 16px 14px;
  }

  #debts .panel-head h3,
  #calendar .panel-head h3 {
    font-size: 1.15rem;
  }

  #debts .panel-head p,
  #calendar .panel-head p {
    font-size: 0.82rem;
  }

  #calendar .filters select {
    padding: 8px 12px;
    font-size: 0.86rem;
    min-height: 38px;
  }

  .payment-list {
    gap: 8px;
  }

  .payment-row {
    grid-template-columns: 40px 1.4fr 0.8fr 0.8fr auto;
    padding: 10px 12px;
    gap: 10px;
    border-radius: var(--radius-md);
  }

  .payment-row .check-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    font-size: 1rem;
  }

  .payment-row strong {
    font-size: 0.94rem;
  }

  .payment-row small {
    font-size: 0.78rem;
  }

  .payment-row .action-link {
    padding: 4px 8px;
    font-size: 0.78rem;
  }

  .payment-row .mini-edit-btn,
  .payment-row .mini-delete-btn {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }

  .payment-row .row-actions {
    gap: 4px;
  }

  .debt-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .debt-card {
    padding: 14px 12px;
    border-radius: var(--radius-md);
  }

  .debt-card h4 {
    font-size: 1rem;
    margin-bottom: 2px;
  }

  .debt-card p {
    font-size: 0.78rem;
  }

  .debt-card .big {
    font-size: 1.38rem;
    margin: 6px 0 4px;
  }

  .debt-meta {
    gap: 6px;
    margin-top: 8px;
  }

  .debt-meta div {
    padding: 6px 8px;
  }

  .debt-meta small {
    font-size: 0.72rem;
  }

  .debt-meta strong {
    font-size: 0.85rem;
  }

  .shared-installment-summary {
    margin-top: 8px;
  }

  .shared-progress-head {
    font-size: 0.8rem;
  }

  .shared-installment-grid {
    gap: 6px;
  }

  .shared-installment-grid > div {
    padding: 6px 8px;
  }

  .shared-installment-grid small {
    font-size: 0.7rem;
  }

  .shared-installment-grid strong {
    font-size: 0.82rem;
  }

  .loan-rounds {
    margin-top: 8px;
    padding: 8px 10px;
  }

  .loan-round {
    padding: 8px 10px;
    margin-top: 4px;
  }

  .loan-round-head strong {
    font-size: 0.84rem;
  }

  .loan-round-head small {
    font-size: 0.72rem;
  }

  .loan-installment {
    padding: 6px 8px;
    font-size: 0.8rem;
  }

  .loan-installment small {
    font-size: 0.72rem;
  }

  .card-actions {
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
  }

  .card-actions > * {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .rotation-summary-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
}

/* ============================================================
   MOBILE PORTRAIT & SMALL SCREENS (มือถือแนวตั้ง)
   ============================================================ */
@media (max-width: 768px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: calc(12px + var(--safe-top)) 14px calc(76px + var(--safe-bottom));
  }

  .topbar {
    position: sticky;
    top: max(8px, var(--safe-top));
    padding: 13px 16px;
    margin-bottom: 16px;
    border-radius: 20px;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #1e3a8a 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 24px -4px rgba(15, 23, 42, 0.35), 0 2px 6px -1px rgba(15, 23, 42, 0.2);
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .topbar-title-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
  }

  .mobile-brand-mini {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70px;
    height: 70px;
    min-width: 70px;
    background: transparent;
    border-radius: 0;
    padding: 0;
  }

  .mobile-brand-mini img {
    width: 70px;
    height: 70px;
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
  }

  .topbar-text-group {
    gap: 4px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .topbar-title-row {
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
  }

  .topbar h2,
  #pageTitle {
    display: none;
  }

  .page-badge,
  #pageBadge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 96.7031px;
    height: 30.3125px;
    padding: 2px 0px 2px 0px;
    border-radius: var(--radius-full);
    font-size: 12.88px;
    font-family: monospace;
    font-weight: 700;
    text-align: center;
    background: rgba(59, 130, 246, 0.28);
    color: #6ea6f9;
    border: 1px solid rgba(147, 197, 253, 0.35);
  }

  .topbar-date-pill,
  #datePill {
    font-size: 0.74rem;
    color: #94a3b8;
    gap: 4px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    align-self: flex-end;
    text-align: right;
  }

  .topbar-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .topbar-add-btn {
    display: none; /* Handled by bottom floating FAB on mobile */
  }

  .mobile-only-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #ffffff;
    font-size: 1rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  }

  .mobile-only-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.2);
  }

  .topbar-account-btn,
  #accountBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    width: 115.516px;
    min-height: 36px;
    font-size: 0.82rem;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  }

  .topbar-account-btn:active,
  #accountBtn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
  }

  .cloud-status,
  #cloudStatus {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 11px;
    width: 115.516px;
    height: 36.7656px;
    font-size: 0.74rem;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #cbd5e1;
  }

  .cloud-status.online,
  #cloudStatus.online {
    background: rgba(22, 163, 74, 0.22);
    border-color: rgba(134, 239, 172, 0.35);
    color: #86efac;
  }

  .cloud-status.error,
  #cloudStatus.error {
    background: rgba(220, 38, 38, 0.22);
    border-color: rgba(254, 202, 202, 0.35);
    color: #fca5a5;
  }

  .status-label {
    display: inline-block; /* Display label in horizontal action bar */
  }

  .fab {
    display: inline-flex;
  }

  .mobile-bottom-nav {
    display: grid;
  }

  /* Layout Collapse for Mobile */
  .hero-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }

  .stat-card {
    padding: 14px 12px;
    border-radius: var(--radius-md);
  }

  .stat-card span {
    font-size: 0.74rem;
  }

  .stat-card strong {
    font-size: 1.25rem;
    margin: 4px 0 2px;
  }

  .stat-card small {
    display: none;
  }

  .grid-2 {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 16px;
  }

  .panel {
    padding: 16px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
  }

  .panel-head.responsive {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .filters {
    width: 100%;
  }

  .filters select {
    flex: 1;
  }

  .mini-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .mini-stats > div {
    padding: 10px 12px;
  }

  .mini-stats strong {
    font-size: 1rem;
  }

  /* Mobile Payment List & Calendar Panel Compact */
  #calendar .panel {
    padding: 12px 10px;
  }

  #calendar .panel-head h3 {
    font-size: 1rem;
  }

  #calendar .panel-head p {
    font-size: 0.75rem;
  }

  #calendar .filters select {
    padding: 6px 10px;
    min-height: 34px;
    font-size: 0.8rem;
  }

  .payment-list {
    gap: 6px;
  }

  .payment-row {
    grid-template-columns: 34px 1fr auto;
    padding: 8px 10px;
    gap: 8px;
    border-radius: var(--radius-sm);
  }

  .payment-row .check-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 0.95rem;
  }

  .payment-row strong {
    font-size: 0.88rem;
  }

  .payment-row small {
    font-size: 0.72rem;
    line-height: 1.25;
  }

  .payment-row .action-link {
    padding: 3px 6px;
    font-size: 0.72rem;
  }

  .payment-row .mini-edit-btn,
  .payment-row .mini-delete-btn {
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }

  .payment-row .row-actions {
    gap: 4px;
    margin-top: 2px;
  }

  .payment-row .hide-mobile {
    display: none;
  }

  /* Mobile Debt Cards & Panel Compact */
  #debts .panel {
    padding: 12px 10px;
  }

  #debts .panel-head h3 {
    font-size: 1rem;
  }

  #debts .panel-head p {
    font-size: 0.75rem;
  }

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

  .debt-card {
    padding: 12px 10px;
    border-radius: var(--radius-sm);
  }

  .debt-card h4 {
    font-size: 0.92rem;
    margin-bottom: 2px;
  }

  .debt-card p {
    font-size: 0.72rem;
  }

  .debt-card .big {
    font-size: 1.25rem;
    margin: 6px 0 4px;
  }

  .debt-meta {
    gap: 6px;
    margin-top: 8px;
  }

  .debt-meta div {
    padding: 5px 8px;
  }

  .debt-meta small {
    font-size: 0.68rem;
  }

  .debt-meta strong {
    font-size: 0.8rem;
  }

  .shared-installment-summary {
    margin-top: 8px;
  }

  .shared-progress-head {
    font-size: 0.75rem;
  }

  .shared-installment-grid {
    gap: 4px;
  }

  .shared-installment-grid > div {
    padding: 4px 6px;
  }

  .shared-installment-grid small {
    font-size: 0.65rem;
  }

  .shared-installment-grid strong {
    font-size: 0.76rem;
  }

  .loan-rounds {
    margin-top: 8px;
    padding: 8px;
  }

  .loan-round {
    padding: 8px;
    margin-top: 4px;
  }

  .loan-round-head strong {
    font-size: 0.8rem;
  }

  .loan-round-head small {
    font-size: 0.68rem;
  }

  .loan-installment {
    padding: 5px 8px;
    font-size: 0.76rem;
  }

  .loan-installment small {
    font-size: 0.68rem;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-top: 10px;
    padding-top: 8px;
  }

  .card-actions > * {
    width: 100%;
    min-height: 32px;
    padding: 6px 8px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
  }

  .card-actions .edit-btn,
  .card-actions .delete-btn,
  .card-actions .mode-btn {
    min-height: 32px;
    padding: 6px 8px;
    font-size: 0.78rem;
  }

  /* Rotation Planner Mobile */
  .planner-start {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .rotation-summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .rotation-step {
    grid-template-columns: 32px 1fr 36px;
    align-items: start;
    gap: 6px;
    padding: 10px;
  }

  .rotation-step .field {
    grid-column: 2;
  }

  .rotation-step .remove-step {
    grid-column: 3;
    grid-row: 1;
  }

  .planner-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .planner-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .saved-plan {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Modals as Bottom Sheets */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-height: 88vh;
    border-radius: 22px 22px 0 0;
    padding: 18px 16px calc(18px + var(--safe-bottom));
  }

  .add-type-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

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

  .field.full {
    grid-column: auto;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
  }

  .modal-actions #saveBtn {
    grid-column: 1 / -1;
  }

  .smart-debt-dynamic {
    grid-template-columns: 1fr;
  }

  .smart-installment-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .shared-installment-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================
   VERY SMALL SCREENS (iPhone SE, < 380px)
   ============================================================ */
@media (max-width: 380px) {
  .hero-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .stat-card {
    padding: 12px 10px;
  }

  .stat-card strong {
    font-size: 1.15rem;
  }

  .mob-text {
    font-size: 0.62rem;
  }
}

/* ============================================================
   PHOSPHOR ICONS STYLING
   ============================================================ */
.ph, .ph-fill {
  vertical-align: middle;
  line-height: 1;
}

.nav-item .ph {
  font-size: 1.25rem;
  margin-right: 12px;
  color: #94a3b8;
  transition: color 0.15s ease;
}
.nav-item:hover .ph {
  color: #ffffff;
}
.nav-item.active .ph {
  color: #ffffff;
}

.sidebar-footer .btn .ph,
.file-label .ph {
  font-size: 1.15rem;
  margin-right: 8px;
}

.topbar-date-pill .date-icon .ph {
  font-size: 1.15rem;
  color: var(--primary);
}

.btn-icon .ph, .account-btn-icon .ph, .mobile-only-btn .ph {
  font-size: 1.25rem;
}

.fab-icon .ph {
  font-size: 1.5rem;
}

.mob-icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.mob-icon .ph {
  font-size: 1.5rem;
  margin-bottom: 2px;
  color: #94a3b8;
  transition: color 0.2s;
}

.mobile-nav-item.active .mob-icon .ph {
  color: var(--primary);
}

.more-item-icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.more-item-icon .ph {
  font-size: 1.5rem;
  color: var(--primary);
}
.more-item.danger .more-item-icon .ph {
  color: var(--danger);
}

.add-type .ph {
  font-size: 1.5rem;
  margin-right: 6px;
  color: var(--primary);
}

.add-type.active .ph {
  color: var(--primary);
}

.mini-edit-btn .ph, .mini-delete-btn .ph {
  font-size: 1.1rem;
}
.mini-delete-btn .ph {
  color: var(--danger);
}

.delete-btn .ph {
  font-size: 1rem;
  margin-right: 4px;
}

.panel-head h3 .ph {
  margin-right: 6px;
  color: var(--primary);
  font-size: 1.3rem;
  vertical-align: -2px;
}


/* ============================================================
   START FRESH / OPENING BALANCE
   ============================================================ */
.start-mode-banner{
  margin-bottom:16px;
  padding:14px 16px;
  border-radius:16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  border:1px solid #bfdbfe;
  background:linear-gradient(135deg,#eff6ff,#f8fbff);
}
.start-mode-banner.future{background:linear-gradient(135deg,#fff7ed,#fffbeb);border-color:#fed7aa}
.start-mode-banner.active{background:linear-gradient(135deg,#f0fdf4,#f8fff9);border-color:#bbf7d0}
.start-mode-banner>div{min-width:0}
.start-mode-banner strong{display:block;font-size:.95rem;color:var(--text)}
.start-mode-banner small{display:block;margin-top:3px;color:var(--muted);font-size:.8rem}
.start-mode-banner .btn{flex-shrink:0}

.start-fresh-modal{max-width:700px}
.start-fresh-guide{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:10px;
  margin-bottom:16px;
}
.guide-step{
  display:flex;
  gap:9px;
  align-items:flex-start;
  padding:12px;
  border:1px solid var(--line);
  border-radius:14px;
  background:#f8fafc;
}
.guide-step>span{
  display:flex;align-items:center;justify-content:center;
  width:26px;height:26px;min-width:26px;border-radius:50%;
  background:var(--primary);color:#fff;font-weight:800;font-size:.78rem;
}
.guide-step strong,.guide-step small{display:block}
.guide-step strong{font-size:.84rem}
.guide-step small{font-size:.72rem;color:var(--muted);margin-top:2px}

.start-fresh-warning{
  display:flex;
  gap:10px;
  padding:12px 14px;
  margin-bottom:16px;
  border:1px solid #fde68a;
  border-radius:14px;
  background:#fffbeb;
  color:#92400e;
}
.start-fresh-warning>i{font-size:1.25rem;margin-top:1px}
.start-fresh-warning strong,.start-fresh-warning small{display:block}
.start-fresh-warning small{margin-top:3px;color:#a16207;font-size:.76rem}

.start-fresh-form{margin-top:0}
.start-fresh-form .field small{display:block;margin-top:5px;color:var(--muted);font-size:.75rem}
.fresh-confirm{
  display:flex;
  gap:9px;
  align-items:flex-start;
  margin-top:14px;
  padding:12px 14px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#f8fafc;
  cursor:pointer;
  font-size:.82rem;
  color:var(--text-secondary);
}
.fresh-confirm input{width:18px;height:18px;flex:0 0 auto;margin-top:1px}
.start-fresh-item .more-item-icon{color:#2563eb}

@media(max-width:700px){
  .start-mode-banner{align-items:flex-start;flex-direction:column}
  .start-mode-banner .btn{width:100%}
  .start-fresh-guide{grid-template-columns:1fr}
  .start-fresh-actions{display:grid;grid-template-columns:1fr}
  .start-fresh-actions .btn{width:100%}
}

div:nth-of-type(1) > main#mainContent:nth-of-type(1) > section#dashboard:nth-of-type(1) > div:nth-of-type(2) {
  grid-template-columns: repeat(4, 1fr) !important;
}

div:nth-of-type(1) > main#mainContent:nth-of-type(1) > section#dashboard:nth-of-type(1) > div:nth-of-type(3) {
  grid-template-columns: 1fr !important;
}

div:nth-of-type(1) > main#mainContent:nth-of-type(1) > section#dashboard:nth-of-type(1) > div:nth-of-type(3) > article:nth-of-type(2) > div#upcomingList:nth-of-type(2) {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 12px !important;
}
.badge-pulse { animation: badgePulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; } @keyframes badgePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; transform: scale(1.02); } }
