/* =====================================================
   Monit — App Styles
   ใช้ Brand CI จาก CHAISANAM brand.css
===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;600;700&family=Sarabun:wght@400;600&display=swap');

:root {
  --c-primary:   #5B9E2A;
  --c-secondary: #7DC944;
  --c-accent:    #C8C8C8;
  --grad-brand:  linear-gradient(135deg, #5B9E2A 0%, #7DC944 100%);
  --grad-soft:   linear-gradient(135deg, #F0F7E8 0%, #F7FBF2 100%);
  --c-bg:        #FFFFFF;
  --c-surface:   #F7FBF2;
  --c-border:    #D4E8C2;
  --c-text:      #0F1F08;
  --c-muted:     #4A6B2A;
  --c-subtle:    #8DAF6A;
  --c-danger:    #DC2626;
  --c-warning:   #D97706;
  --c-info:      #0891B2;
  --font-primary: 'Kanit', sans-serif;
  --font-body:    'Sarabun', sans-serif;
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   24px;
  --r-full: 9999px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-brand: 0 4px 20px rgba(91,158,42,0.30);
  --nav-h: 68px;
  --transition: 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Login Page ──────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--grad-soft);
  padding: 24px;
}

.login-logo {
  width: 80px;
  height: 80px;
  background: var(--grad-brand);
  border-radius: var(--r-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-primary);
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  box-shadow: var(--shadow-brand);
  margin-bottom: 16px;
}

.login-title {
  font-family: var(--font-primary);
  font-size: 32px;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--c-muted);
  margin-bottom: 48px;
}

.login-card {
  background: var(--c-bg);
  border-radius: var(--r-xl);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--c-border);
}

.login-card h2 {
  font-family: var(--font-primary);
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-card p {
  font-size: 14px;
  color: var(--c-muted);
  margin-bottom: 28px;
  line-height: 1.6;
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 24px;
  border-radius: var(--r-full);
  border: none;
  font-family: var(--font-primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-brand {
  background: var(--grad-brand);
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn-brand:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-brand:active { transform: translateY(0); }

.btn-outline {
  background: transparent;
  color: var(--c-primary);
  border: 1.5px solid var(--c-primary);
}
.btn-outline:hover { background: var(--c-surface); }

.btn-google {
  background: #fff;
  color: #1a1a1a;
  border: 1.5px solid #E0E0E0;
  box-shadow: var(--shadow-sm);
}
.btn-google:hover { background: #F8F8F8; }

.btn + .btn { margin-top: 12px; }

/* ── App Layout ──────────────────────────────────── */
.app-page {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: var(--nav-h);
}
.app-page.active { display: flex; }

/* ── Top Bar ─────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-brand {
  font-family: var(--font-primary);
  font-size: 22px;
  font-weight: 700;
  color: var(--c-primary);
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--grad-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-primary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* ── Scroll Content ──────────────────────────────── */
.scroll-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
}

/* ── Summary Cards ───────────────────────────────── */
.summary-banner {
  background: var(--grad-brand);
  border-radius: var(--r-xl);
  padding: 24px 20px 20px;
  color: #fff;
  margin-bottom: 16px;
  box-shadow: var(--shadow-brand);
}

.summary-banner .period-label {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 4px;
}

.summary-banner .balance-label {
  font-size: 13px;
  opacity: 0.85;
}

.summary-banner .balance-amount {
  font-family: var(--font-primary);
  font-size: 34px;
  font-weight: 700;
  margin-bottom: 20px;
}

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

.summary-mini {
  background: rgba(255,255,255,0.18);
  border-radius: var(--r-md);
  padding: 12px;
}

.summary-mini .label {
  font-size: 12px;
  opacity: 0.85;
  margin-bottom: 2px;
}

.summary-mini .amount {
  font-family: var(--font-primary);
  font-size: 18px;
  font-weight: 600;
}

/* ── Period Selector ─────────────────────────────── */
.period-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.period-tab {
  flex: 1;
  padding: 8px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-full);
  background: transparent;
  font-family: var(--font-primary);
  font-size: 13px;
  color: var(--c-muted);
  cursor: pointer;
  transition: var(--transition);
}

.period-tab.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}

/* ── Section ─────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-family: var(--font-primary);
  font-size: 16px;
  font-weight: 600;
}

.section-link {
  font-size: 13px;
  color: var(--c-primary);
  cursor: pointer;
  text-decoration: none;
}

/* ── Transaction Item ────────────────────────────── */
.txn-list { display: flex; flex-direction: column; gap: 8px; }

.txn-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.txn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--c-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.txn-info { flex: 1; min-width: 0; }

.txn-name {
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-date { font-size: 12px; color: var(--c-subtle); }

.txn-amount {
  font-family: var(--font-primary);
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.txn-amount.income { color: var(--c-primary); }
.txn-amount.expense { color: var(--c-danger); }

/* ── AI Insight Button ───────────────────────────── */
.ai-insight-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  border: none;
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.20);
  transition: var(--transition);
}

.ai-insight-btn:hover { filter: brightness(1.15); transform: translateY(-1px); }
.ai-insight-btn .ai-badge {
  background: linear-gradient(135deg, #7C3AED, #0891B2);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--r-full);
}

/* ── Bottom Navigation ───────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--c-bg);
  border-top: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: var(--transition);
}

.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-family: var(--font-primary); font-size: 10px; color: var(--c-subtle); }
.nav-item.active .nav-label { color: var(--c-primary); }
.nav-item.active .nav-icon { filter: none; }

/* FAB — Add Button กลาง nav */
.nav-fab {
  width: 52px;
  height: 52px;
  background: var(--grad-brand);
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-brand);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.nav-fab:hover { filter: brightness(1.08); transform: scale(1.05); }
.nav-fab svg { width: 26px; height: 26px; stroke: #fff; }

/* ── Empty State ─────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--c-subtle);
}

.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ── Toast ───────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a1a;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--r-full);
  font-family: var(--font-primary);
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
  z-index: 999;
}

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

/* ── Transaction List ────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-select {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-full);
  background: var(--c-bg);
  font-family: var(--font-primary);
  font-size: 13px;
  color: var(--c-text);
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.filter-select:focus { border-color: var(--c-primary); }

.txn-summary-strip {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.strip-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  text-align: center;
}

.strip-card .s-label { font-size: 11px; color: var(--c-subtle); margin-bottom: 2px; }
.strip-card .s-amount { font-family: var(--font-primary); font-size: 14px; font-weight: 700; }
.strip-card .s-amount.income  { color: var(--c-primary); }
.strip-card .s-amount.expense { color: var(--c-danger); }
.strip-card .s-amount.balance { color: var(--c-text); }

.txn-date-group {
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-subtle);
  padding: 12px 4px 6px;
}

.txn-item { cursor: pointer; }
.txn-item:active { opacity: 0.7; }

/* ── Add Entry ───────────────────────────────────── */
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--c-surface);
  border-radius: var(--r-full);
  padding: 4px;
  margin-bottom: 20px;
  border: 1px solid var(--c-border);
}

.type-btn {
  padding: 10px;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  font-family: var(--font-primary);
  font-size: 15px;
  font-weight: 600;
  color: var(--c-muted);
  cursor: pointer;
  transition: var(--transition);
}

.type-btn.active {
  background: var(--c-bg);
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
}

.type-btn.active[data-type="expense"] { color: var(--c-danger); }
.type-btn.active[data-type="income"]  { color: var(--c-primary); }

.amount-field-wrap {
  display: flex;
  align-items: center;
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 12px 20px;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}

.amount-field-wrap:focus-within { border-color: var(--c-primary); }

.amount-currency {
  font-family: var(--font-primary);
  font-size: 28px;
  font-weight: 700;
  color: var(--c-subtle);
  margin-right: 8px;
}

.amount-field {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-primary);
  font-size: 36px;
  font-weight: 700;
  color: var(--c-text);
  outline: none;
  width: 100%;
}

.amount-field::placeholder { color: var(--c-accent); }

/* ── Voice ───────────────────────────────────────── */
.voice-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 24px;
}

.voice-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--grad-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-brand);
  transition: var(--transition);
  margin-bottom: 10px;
}

.voice-btn svg { width: 32px; height: 32px; }
.voice-btn:hover { filter: brightness(1.1); transform: scale(1.05); }
.voice-btn:active { transform: scale(0.96); }

.voice-btn.listening {
  background: linear-gradient(135deg, #DC2626, #EF4444);
  box-shadow: 0 0 0 0 rgba(220,38,38,0.4);
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0%   { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
  70%  { box-shadow: 0 0 0 16px rgba(220,38,38,0); }
  100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
}

.voice-btn.processing {
  background: linear-gradient(135deg, #7C3AED, #0891B2);
  animation: none;
}

.voice-label {
  font-size: 13px;
  color: var(--c-subtle);
  text-align: center;
}

.voice-transcript {
  margin-top: 8px;
  font-family: var(--font-primary);
  font-size: 15px;
  font-weight: 600;
  color: var(--c-primary);
  text-align: center;
  min-height: 20px;
}

/* ── Category Grid ───────────────────────────────── */
.field-label {
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-muted);
  margin-bottom: 10px;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
  cursor: pointer;
  transition: var(--transition);
}

.cat-item:hover { border-color: var(--c-primary); background: var(--c-surface); }
.cat-item.selected { border-color: var(--c-primary); background: var(--c-surface); }

.cat-item .cat-emoji { font-size: 24px; line-height: 1; }
.cat-item .cat-name  { font-family: var(--font-primary); font-size: 11px; color: var(--c-muted); text-align: center; }
.cat-item.selected .cat-name { color: var(--c-primary); font-weight: 600; }

/* ── Budget ──────────────────────────────────────── */
.budget-item {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
}
.budget-item:hover { border-color: var(--c-primary); }

.budget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.budget-cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-primary);
  font-size: 15px;
  font-weight: 600;
}

.budget-amounts {
  font-family: var(--font-primary);
  font-size: 13px;
  text-align: right;
}

.budget-spent  { color: var(--c-text); font-weight: 600; }
.budget-limit  { color: var(--c-subtle); }

.budget-bar-bg {
  height: 8px;
  background: var(--c-surface);
  border-radius: var(--r-full);
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: var(--r-full);
  transition: width 0.4s ease;
}

.budget-bar-fill.safe    { background: var(--grad-brand); }
.budget-bar-fill.warning { background: linear-gradient(90deg, #D97706, #F59E0B); }
.budget-bar-fill.danger  { background: linear-gradient(90deg, #DC2626, #EF4444); }

.budget-pct {
  font-family: var(--font-primary);
  font-size: 12px;
  color: var(--c-subtle);
  text-align: right;
  margin-top: 4px;
}

.notify-pct-btn {
  flex: 1;
  padding: 8px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-full);
  background: transparent;
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-muted);
  cursor: pointer;
  transition: var(--transition);
}
.notify-pct-btn.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}

/* ── Modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  padding: 0;
}

.modal-card {
  background: var(--c-bg);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 24px 20px 40px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
}

.modal-title {
  font-family: var(--font-primary);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ── AI Topic Sheet ──────────────────────────────── */
.ai-topic-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ai-topic-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 12px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-bg);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}
.ai-topic-btn:hover  { border-color: var(--c-primary); background: var(--c-surface); }
.ai-topic-btn:active { transform: scale(0.97); }

.topic-icon { font-size: 28px; line-height: 1; margin-bottom: 2px; }
.topic-name { font-family: var(--font-primary); font-size: 13px; font-weight: 700; color: var(--c-text); }
.topic-desc { font-size: 11px; color: var(--c-subtle); line-height: 1.4; }

/* ── AI Insight Modal ────────────────────────────── */
.ai-modal-result {
  background: var(--c-surface);
  border-radius: var(--r-md);
  padding: 16px;
  font-size: 14px;
  line-height: 1.8;
  color: var(--c-text);
  white-space: pre-wrap;
  margin-top: 16px;
  max-height: 60dvh;
  overflow-y: auto;
}

/* ── Settings ────────────────────────────────────── */
.settings-section { margin-bottom: 24px; }

.settings-title {
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.settings-card {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

.settings-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--grad-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-primary);
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.settings-name  { font-family: var(--font-primary); font-size: 16px; font-weight: 600; }
.settings-email { font-size: 13px; color: var(--c-subtle); margin-top: 2px; }
.settings-desc  { font-size: 14px; color: var(--c-muted); line-height: 1.6; margin-bottom: 12px; }

.line-steps { margin-bottom: 12px; }
.line-step {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--c-text);
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.line-code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  gap: 8px;
}

#line-code-text {
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-primary);
  word-break: break-all;
}

.line-copy-btn {
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  padding: 6px 12px;
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition);
}
.line-copy-btn:hover { filter: brightness(1.1); }

.line-connected-badge {
  font-family: var(--font-primary);
  font-size: 16px;
  font-weight: 600;
  color: var(--c-primary);
  margin-bottom: 4px;
}

/* ── Loading ─────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
