/* ===== CSS Variables ===== */
:root {
  --primary: #6c63ff;
  --primary-light: #a29bfe;
  --secondary: #fd79a8;
  --success: #00b894;
  --warning: #fdcb6e;
  --danger: #d63031;
  --info: #0984e3;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --sidebar-bg: #1e1e2e;
  --sidebar-text: #cdd6f4;
  --sidebar-active: #6c63ff;
  --text: #2d3436;
  --text-muted: #636e72;
  --border: #e0e0e0;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --radius: 12px;
  --topbar-h: 60px;
  --sidebar-w: 240px;
  --transition: 0.3s ease;
  /* Mobile safe area for notches/status bar */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --card-bg: #16213e;
  --text: #e0e0e0;
  --text-muted: #a0a0b0;
  --border: #2a2a4a;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  /* Enable safe area support */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
body { 
  font-family: 'Segoe UI', system-ui, sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  transition: background var(--transition), color var(--transition);
  /* Add top padding for mobile status bar */
  padding-top: env(safe-area-inset-top, 0px);
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed; 
  top: 0; 
  left: 0; 
  height: 100vh; 
  width: var(--sidebar-w);
  background: var(--sidebar-bg); 
  color: var(--sidebar-text);
  display: flex; 
  flex-direction: column; 
  z-index: 1000;
  transition: transform var(--transition);
  overflow-y: auto;
  /* Account for safe area on mobile */
  padding-top: env(safe-area-inset-top, 0px);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.logo { font-size: 1.2rem; font-weight: 700; color: var(--primary-light); display: flex; align-items: center; gap: 8px; }
.sidebar-close { color: var(--sidebar-text); font-size: 1.1rem; display: none; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  color: var(--sidebar-text); font-size: 0.9rem; transition: all var(--transition);
  position: relative; border-radius: 0 24px 24px 0; margin-right: 12px;
}
.nav-item:hover, .nav-item.active { background: rgba(108,99,255,0.2); color: var(--primary-light); }
.nav-item.active { border-left: 3px solid var(--primary); }
.nav-item .badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px; padding: 2px 7px; font-size: 0.72rem; font-weight: 700; }
.nav-item i { width: 18px; text-align: center; }
.sidebar-footer { padding: 12px 0; border-top: 1px solid rgba(255,255,255,0.08); }
.nav-item.logout:hover { background: rgba(214,48,49,0.2); color: #ff7675; }
.ikon-nav-item { border-top: 1px solid rgba(255,255,255,0.1); margin-top: 4px; }

/* ===== Topbar ===== */
.topbar {
  position: fixed; 
  top: env(safe-area-inset-top, 0px); 
  left: var(--sidebar-w); 
  right: 0; 
  height: var(--topbar-h);
  background: var(--card-bg); 
  border-bottom: 1px solid var(--border);
  display: flex; 
  align-items: center; 
  padding: 0 20px; 
  gap: 12px;
  z-index: 900; 
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: left var(--transition), background var(--transition);
}
.menu-btn { font-size: 1.2rem; color: var(--text-muted); display: none; }
.topbar-title { font-weight: 700; font-size: 1.1rem; color: var(--primary); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 1rem; transition: all var(--transition); position: relative; }
.icon-btn:hover { background: var(--bg); color: var(--primary); }
.ikon-btn { width: auto; padding: 0 10px; border-radius: 20px; gap: 5px; font-size: 0.85rem; font-weight: 600; color: var(--primary); text-decoration: none; }
.ikon-text { font-size: 0.8rem; }
.notif-badge { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff; border-radius: 50%; width: 16px; height: 16px; font-size: 0.65rem; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.notif-wrap { position: relative; }
.notif-dropdown {
  position: absolute; top: 48px; right: 0; width: 320px; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  display: none; z-index: 999; max-height: 400px; overflow-y: auto;
}
.notif-dropdown.open { display: block; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.notif-item:last-child { border-bottom: none; }
.notif-item.urgent { border-left: 3px solid var(--danger); }
.notif-item.pending { border-left: 3px solid var(--warning); }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; cursor: pointer; }

/* ===== Main Content ===== */
.main-content { margin-left: var(--sidebar-w); margin-top: var(--topbar-h); padding: 24px; min-height: calc(100vh - var(--topbar-h)); transition: margin-left var(--transition); }

/* ===== Cards ===== */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; border: 1px solid var(--border); transition: background var(--transition); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; border: 1px solid var(--border); }
.stat-icon { width: 52px; height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.stat-icon.purple { background: rgba(108,99,255,0.15); color: var(--primary); }
.stat-icon.green { background: rgba(0,184,148,0.15); color: var(--success); }
.stat-icon.orange { background: rgba(253,203,110,0.2); color: #e17055; }
.stat-icon.pink { background: rgba(253,121,168,0.15); color: var(--secondary); }
.stat-icon.blue { background: rgba(9,132,227,0.15); color: var(--info); }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ===== Grid Layouts ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 0.9rem; background: var(--bg); color: var(--text);
  transition: border-color var(--transition), background var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--primary); background: var(--card-bg); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; transition: all var(--transition); cursor: pointer; border: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #5a52d5; transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #00a381; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: var(--warning); color: #2d3436; }
.btn-warning:hover { background: #f9ca24; }
.btn-info { background: var(--info); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { background: var(--bg); color: var(--text-muted); font-weight: 600; padding: 10px 14px; text-align: left; border-bottom: 2px solid var(--border); }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
tr:hover td { background: rgba(108,99,255,0.04); }

/* ===== Badges / Pills ===== */
.pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.pill-high { background: rgba(214,48,49,0.12); color: var(--danger); }
.pill-medium { background: rgba(253,203,110,0.2); color: #e17055; }
.pill-low { background: rgba(0,184,148,0.12); color: var(--success); }
.pill-pending { background: rgba(253,203,110,0.2); color: #e17055; }
.pill-completed { background: rgba(0,184,148,0.12); color: var(--success); }
.pill-overdue { background: rgba(214,48,49,0.12); color: var(--danger); }

/* ===== Alerts ===== */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; }
.alert-success { background: rgba(0,184,148,0.12); color: var(--success); border: 1px solid rgba(0,184,148,0.3); }
.alert-error { background: rgba(214,48,49,0.1); color: var(--danger); border: 1px solid rgba(214,48,49,0.3); }
.alert-warning { background: rgba(253,203,110,0.15); color: #e17055; border: 1px solid rgba(253,203,110,0.4); }
.alert button { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: inherit; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-header { padding: 20px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { font-size: 1.3rem; color: var(--text-muted); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Voice Button ===== */
.voice-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1rem; transition: all var(--transition); flex-shrink: 0; }
.voice-btn.recording { background: var(--danger); animation: pulse 1s infinite; }
.voice-input-wrap { display: flex; gap: 8px; align-items: flex-start; }
.voice-input-wrap .form-control { flex: 1; }
@keyframes pulse { 0%,100%{transform:scale(1);} 50%{transform:scale(1.1);} }

/* ===== Priority Colors ===== */
.priority-high { color: var(--danger); }
.priority-medium { color: #e17055; }
.priority-low { color: var(--success); }

/* ===== Task Item ===== */
.task-item { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 10px; background: var(--card-bg); transition: all var(--transition); }
.task-item:hover { box-shadow: var(--shadow); }
.task-item.completed { opacity: 0.6; }
.task-item.completed .task-title { text-decoration: line-through; }
.task-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; flex-shrink: 0; margin-top: 2px; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.task-check.checked { background: var(--success); border-color: var(--success); color: #fff; }
.task-body { flex: 1; }
.task-title { font-weight: 600; font-size: 0.92rem; margin-bottom: 4px; }
.task-meta { font-size: 0.78rem; color: var(--text-muted); display: flex; gap: 12px; flex-wrap: wrap; }
.task-actions { display: flex; gap: 6px; }

/* ===== Note Card ===== */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.note-card { background: var(--card-bg); border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); box-shadow: var(--shadow); position: relative; transition: all var(--transition); }
.note-card:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,0.12); }
.note-card.pinned { border-top: 3px solid var(--primary); }
.note-card .pin-icon { position: absolute; top: 12px; right: 12px; color: var(--primary); font-size: 0.85rem; }
.note-title { font-weight: 700; margin-bottom: 8px; font-size: 0.95rem; }
.note-content { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; max-height: 80px; overflow: hidden; }
.note-footer { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); }

/* ===== Expense ===== */
.expense-amount { font-size: 1.1rem; font-weight: 700; color: var(--danger); }

/* ===== Meeting ===== */
.meeting-item { padding: 14px; border-radius: 10px; border-left: 4px solid var(--primary); background: var(--card-bg); margin-bottom: 10px; box-shadow: var(--shadow); }
.meeting-title { font-weight: 700; margin-bottom: 4px; }
.meeting-meta { font-size: 0.8rem; color: var(--text-muted); }

/* ===== Auth Pages ===== */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; }
.auth-card { background: #fff; border-radius: 20px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo i { font-size: 2.5rem; color: var(--primary); }
.auth-logo h1 { font-size: 1.5rem; font-weight: 800; color: #2d3436; margin-top: 8px; }
.auth-logo p { color: #636e72; font-size: 0.9rem; }
.auth-card .form-control { background: #f8f9fa; border-color: #e9ecef; }
.auth-card .form-control:focus { background: #fff; }
.auth-link { text-align: center; margin-top: 20px; font-size: 0.88rem; color: #636e72; }
.auth-link a { color: var(--primary); font-weight: 600; }

/* ===== Search ===== */
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; }
.search-bar .form-control { flex: 1; }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.filter-bar select, .filter-bar input { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--card-bg); color: var(--text); font-size: 0.85rem; outline: none; }

/* ===== Page Header ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 1.4rem; font-weight: 800; color: var(--text); }
.page-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.95rem; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .topbar { left: 0; }
  .main-content { margin-left: 0; }
  .menu-btn { display: flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
  .notes-grid { grid-template-columns: 1fr; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Overlay for mobile sidebar ===== */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; }
.sidebar-overlay.open { display: block; }

/* ===== Chart container ===== */
.chart-container { position: relative; height: 260px; }

/* ===== Reminder types ===== */
.reminder-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.reminder-icon.bill { background: rgba(214,48,49,0.12); color: var(--danger); }
.reminder-icon.birthday { background: rgba(253,121,168,0.15); color: var(--secondary); }
.reminder-icon.habit { background: rgba(0,184,148,0.12); color: var(--success); }
.reminder-icon.recharge { background: rgba(9,132,227,0.15); color: var(--info); }
.reminder-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 8px; background: var(--card-bg); }
.reminder-body { flex: 1; }
.reminder-title { font-weight: 600; font-size: 0.9rem; }
.reminder-meta { font-size: 0.78rem; color: var(--text-muted); }

/* ===== Progress bar ===== */
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; border-radius: 4px; background: var(--primary); transition: width 0.5s ease; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn { padding: 10px 18px; font-size: 0.88rem; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all var(--transition); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }
