/* ===================== Design tokens ===================== */
:root {
  --color-primary: #1e3a5f;
  --color-primary-light: #2c5282;
  --color-accent: #0d9488;
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-green: #16a34a;
  --color-green-bg: #dcfce7;
  --color-red: #dc2626;
  --color-red-bg: #fee2e2;
  --color-orange: #ea580c;
  --color-orange-bg: #ffedd5;
  --color-yellow: #d97706;
  --color-yellow-bg: #fef3c7;
  --color-blue: #2563eb;
  --color-blue-bg: #dbeafe;
  --color-gray-bg: #f1f5f9;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --sidebar-width: 250px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

.hidden { display: none !important; }

/* ===================== App layout ===================== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--color-primary) 0%, #16283f 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand i { font-size: 22px; color: #5eead4; }
.brand-title { font-weight: 700; font-size: 15px; color: #fff; }
.brand-sub { font-size: 11px; color: #94a3b8; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; font-size: 13.5px;
  color: #cbd5e1; transition: background .15s;
}
.nav-item i { width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item-active { background: rgba(94, 234, 212, 0.15); color: #5eead4; font-weight: 600; }

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-mini { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--color-accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-mini-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-mini-role { font-size: 11px; color: #94a3b8; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px; background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 18px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 8px; border: none; background: transparent;
  color: var(--color-text-muted); font-size: 16px; display: flex; align-items: center; justify-content: center;
  position: relative; transition: background .15s;
}
.icon-btn:hover { background: var(--color-gray-bg); color: var(--color-text); }
.notif-badge {
  position: absolute; top: 2px; right: 2px; background: var(--color-red); color: #fff;
  font-size: 10px; border-radius: 50%; min-width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.notif-wrap, .user-menu-wrap { position: relative; }
.notif-panel, .user-menu-panel {
  position: absolute; top: 46px; right: 0; width: 320px; background: #fff; border-radius: 10px;
  box-shadow: var(--shadow-md); border: 1px solid var(--color-border); max-height: 420px; overflow-y: auto; z-index: 50;
}
.notif-panel-header { padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--color-border); }
.notif-empty { padding: 24px; text-align: center; color: var(--color-text-muted); }
.notif-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #f1f5f9; }
.notif-item-unread { background: #f8fafc; }
.notif-item-icon { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 13px; }
.notif-info { background: var(--color-blue-bg); color: var(--color-blue); }
.notif-warning { background: var(--color-yellow-bg); color: var(--color-yellow); }
.notif-error, .notif-danger { background: var(--color-red-bg); color: var(--color-red); }
.notif-item-title { font-weight: 600; font-size: 13px; }
.notif-item-msg { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }
.notif-item-time { font-size: 11px; color: #94a3b8; margin-top: 4px; }
.user-menu-header { padding: 14px 16px; border-bottom: 1px solid var(--color-border); }
.user-menu-name { font-weight: 700; }
.user-menu-email { font-size: 12px; color: var(--color-text-muted); }
.user-menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 12px 16px;
  border: none; background: none; font-size: 13.5px; color: var(--color-text);
}
.user-menu-item:hover { background: var(--color-gray-bg); }

.page-content { padding: 22px; flex: 1; }

/* ===================== Cards / KPI ===================== */
.card {
  background: var(--color-surface); border-radius: var(--radius); border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm); padding: 18px;
}
.card-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; display:flex; align-items:center; justify-content:space-between;}
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  background: var(--color-surface); border-radius: var(--radius); border: 1px solid var(--color-border);
  padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi-label { font-size: 12.5px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 24px; font-weight: 800; margin-top: 8px; }
.kpi-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.kpi-icon { position: absolute; right: 14px; top: 14px; font-size: 22px; opacity: .18; }
.kpi-green .kpi-value, .value-positive { color: var(--color-green); }
.kpi-red .kpi-value, .value-negative { color: var(--color-red); }
.kpi-blue .kpi-value { color: var(--color-blue); }
.kpi-orange .kpi-value { color: var(--color-orange); }

.section-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; border: 1px solid transparent; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-light); }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-accent:hover { background: #0f766e; }
.btn-outline { background: #fff; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-gray-bg); }
.btn-danger { background: var(--color-red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===================== Forms ===================== */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--color-text-muted); }
.form-control {
  width: 100%; padding: 9px 12px; border: 1px solid var(--color-border); border-radius: 8px; background: #fff; color: var(--color-text);
}
.form-control:focus { outline: none; border-color: var(--color-primary-light); box-shadow: 0 0 0 3px rgba(44,82,130,.12); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ===================== Table ===================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--color-border); background: #fff; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 700px; }
table.data-table th {
  background: #f8fafc; text-align: left; padding: 10px 14px; font-weight: 700; color: var(--color-text-muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--color-border); white-space: nowrap;
}
table.data-table td { padding: 10px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table.data-table tbody tr:hover { background: #f8fafc; }
table.data-table tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.num-cell { font-family: "SF Mono", Consolas, monospace; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-blue { background: var(--color-blue-bg); color: var(--color-blue); }
.badge-orange { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-yellow { background: var(--color-yellow-bg); color: var(--color-yellow); }
.type-inflow { color: var(--color-green); font-weight: 700; }
.type-outflow { color: var(--color-red); font-weight: 700; }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filter-bar .form-control { width: auto; min-width: 140px; }
.search-input-wrap { position: relative; }
.search-input-wrap i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.search-input-wrap input { padding-left: 34px; min-width: 220px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-box.modal-lg { max-width: 900px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--color-border); position: sticky; top: 0; background: #fff; z-index: 5;}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: #fff; }
.modal-close-btn { border: none; background: none; font-size: 18px; color: var(--color-text-muted); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 18px; }
.tab-item { padding: 10px 16px; font-size: 13.5px; font-weight: 600; color: var(--color-text-muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tab-item.tab-active { color: var(--color-primary); border-color: var(--color-primary); }

/* Login */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a5f, #0d9488); padding: 20px; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow-md); padding: 36px; width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand i { font-size: 34px; color: var(--color-accent); }
.auth-brand h1 { font-size: 20px; margin-top: 10px; }
.auth-brand p { font-size: 12.5px; color: var(--color-text-muted); margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 16px; font-size: 13px; color: var(--color-text-muted); }
.auth-error { background: var(--color-red-bg); color: var(--color-red); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.auth-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: #94a3b8; font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--color-border); }
.btn-google { width: 100%; justify-content: center; background: #fff; border: 1px solid var(--color-border); color: var(--color-text); }

/* Cash gap banner */
.alert-banner { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border-radius: 10px; margin-bottom: 16px; }
.alert-danger { background: var(--color-red-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--color-yellow-bg); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--color-blue-bg); color: #1e40af; border: 1px solid #bfdbfe; }
.alert-banner i { font-size: 18px; margin-top: 2px; }
.alert-banner-title { font-weight: 700; font-size: 13.5px; }
.alert-banner-msg { font-size: 12.5px; margin-top: 2px; }

/* Empty state */
.empty-state { text-align: center; padding: 50px 20px; color: var(--color-text-muted); }
.empty-state i { font-size: 36px; margin-bottom: 12px; opacity: .4; }

/* Loading */
.spinner { width: 24px; height: 24px; border: 3px solid #e2e8f0; border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font-size: 12.5px; color: var(--color-text-muted); }
.pagination-btns { display: flex; gap: 6px; }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--color-text-muted); margin-bottom: 16px; flex-wrap: wrap; }
.breadcrumb a { color: var(--color-primary-light); font-weight: 600; }
.breadcrumb i { font-size: 10px; }

/* Progress bar */
.progress-track { height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--color-accent); border-radius: 4px; }

/* Calendar */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar-day-head { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--color-text-muted); padding: 6px 0; text-transform: uppercase; }
.calendar-cell {
  min-height: 92px; border: 1px solid var(--color-border); border-radius: 8px; padding: 6px 8px; cursor: pointer; background: #fff; transition: background .15s;
}
.calendar-cell:hover { background: #f8fafc; }
.calendar-cell.calendar-cell-empty { background: #fafbfc; cursor: default; }
.calendar-cell.calendar-cell-today { border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent) inset; }
.calendar-date-num { font-size: 12.5px; font-weight: 700; }
.calendar-amt-in { font-size: 11px; color: var(--color-green); font-weight: 700; margin-top: 4px; }
.calendar-amt-out { font-size: 11px; color: var(--color-red); font-weight: 700; }

/* Drag helpers */
.clickable { cursor: pointer; }
.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0 !important;}
.mb-0 { margin-bottom: 0 !important; }

/* ===================== Responsive ===================== */
.mobile-only { display: none; }

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .section-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .mobile-only { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 200; transform: translateX(-100%); transition: transform .2s; height: 100vh;
  }
  .sidebar.sidebar-open { transform: translateX(0); }
  .kpi-grid { grid-template-columns: 1fr; }
  .page-content { padding: 14px; }
  .notif-panel, .user-menu-panel { width: 280px; right: -10px; }
  .page-title { font-size: 15px; }
}
