/* ─── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface-2:   #252836;
  --surface-3:   #2d3148;
  --border:      #2d3148;
  --accent:      #4f8ef7;
  --accent-dim:  #3a6fd8;
  --text:        #e8eaf0;
  --text-muted:  #8b8fa8;
  --success:     #22c55e;
  --error:       #ef4444;
  --warning:     #f59e0b;
  --mono:        'Courier New', 'Lucida Console', monospace;
  --radius:      10px;
  --sidebar-w:   220px;
  --shadow:      0 4px 24px rgba(0,0,0,.45);
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }

/* ─── Login Page ────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 60% 30%, #1a2340 0%, var(--bg) 70%);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-logo svg { color: var(--accent); }

.auth-logo h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  border: none;
  background: none;
}

.auth-tab.active {
  background: var(--surface-2);
  color: var(--text);
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}

.form-group input, .form-group select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 12px;
}

.btn-primary:hover { background: var(--accent-dim); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface-3); }

.btn-danger {
  background: var(--error);
  color: #fff;
}

.btn-danger:hover { opacity: .85; }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.auth-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: var(--error);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.auth-error.show { display: block; }

/* ─── App Shell ─────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo svg { color: var(--accent); }

.sidebar-logo span {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-link.active {
  background: rgba(79,142,247,.15);
  color: var(--accent);
}

.sidebar-bottom {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.user-avatar {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all .15s;
}

.btn-logout:hover {
  background: rgba(239,68,68,.1);
  color: var(--error);
}

/* ─── Main Content ──────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.view {
  display: none;
  padding: 28px;
  max-width: 960px;
  margin: 0 auto;
}

.view.active { display: block; }

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

.view-title {
  font-size: 20px;
  font-weight: 700;
}

.view-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ─── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ─── Dashboard ─────────────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
}

@media (max-width: 700px) {
  .dash-grid { grid-template-columns: 1fr; }
}

.balance-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 140px;
  position: relative;
  overflow: hidden;
}

.balance-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  opacity: .08;
  pointer-events: none;
  transition: background .3s;
}

.balance-card.positive::before { background: var(--success); }
.balance-card.negative::before { background: var(--error); }

.balance-value {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
  transition: color .3s;
}

.balance-value.positive { color: var(--success); }
.balance-value.negative { color: var(--error); }

.balance-label {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Entry form */
.entry-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

@media (max-width: 600px) {
  .entry-form { grid-template-columns: 1fr 1fr; }
}

.entry-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* Smart Planner */
.planner-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.planner-stat {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border);
}

.planner-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 4px;
}

.planner-stat-value {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.planner-stat-value.countdown {
  font-size: 15px;
  color: var(--text);
}

/* Timeline */
.timeline-wrap {
  margin-bottom: 16px;
}

.timeline-bar {
  position: relative;
  height: 36px;
  background: var(--bg);
  border-radius: 8px;
  overflow: visible;
  border: 1px solid var(--border);
}

.tl-segment {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 4px;
}

.tl-work { background: rgba(79,142,247,.25); border: 1px solid rgba(79,142,247,.5); }
.tl-break { background: rgba(245,158,11,.25); border: 1px solid rgba(245,158,11,.5); }

.tl-marker {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 2px;
  border-radius: 2px;
}

.tl-marker-label {
  position: absolute;
  top: 42px;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  font-family: var(--mono);
}

.tl-start { background: var(--success); }
.tl-core-end { background: var(--warning); }
.tl-departure { background: var(--accent); }
.tl-now { background: rgba(255,255,255,.4); }

.timeline-legend {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.tl-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.tl-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Calendar ──────────────────────────────────────────────────── */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.cal-nav-title {
  font-size: 16px;
  font-weight: 600;
}

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

.cal-weekday {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 6px 0;
}

.cal-day {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all .12s;
  background: var(--surface-2);
  position: relative;
  gap: 2px;
  padding: 4px;
}

.cal-day:hover { border-color: var(--accent); }

.cal-day.empty {
  background: transparent;
  cursor: default;
}

.cal-day.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.cal-day.positive { background: rgba(34,197,94,.15); }
.cal-day.negative { background: rgba(239,68,68,.12); }
.cal-day.weekend { background: var(--surface); opacity: .6; }

.cal-day-num { font-size: 13px; font-weight: 600; }
.cal-day-delta {
  font-size: 9px;
  font-family: var(--mono);
  opacity: .8;
}

/* ─── Overview ──────────────────────────────────────────────────── */
.week-section { margin-bottom: 24px; }

.week-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 6px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(45,49,72,.5);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--surface-2); }

.mono { font-family: var(--mono); }

.positive { color: var(--success); }
.negative { color: var(--error); }
.muted { color: var(--text-muted); }

.week-totals td {
  font-weight: 600;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12px;
}

/* ─── Reports ───────────────────────────────────────────────────── */
.reports-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

@media (max-width: 600px) {
  .reports-grid { grid-template-columns: 1fr; }
}

.export-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-card-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.export-card-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.range-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.preset-btn {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .12s;
}

.preset-btn:hover, .preset-btn.active {
  background: rgba(79,142,247,.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Settings ──────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  grid-column: 1 / -1;
}

/* ─── Settings tabs ─────────────────────────────────────────────── */
.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.settings-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  margin-bottom: -1px;
  transition: color .12s, border-color .12s;
}

.settings-tab:hover { color: var(--text); }

.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.settings-tab-content { display: none; }
.settings-tab-content.active { display: block; }

/* ─── Badge swipe overlay ────────────────────────────────────────── */
.swipe-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px 20px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.swipe-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

.swipe-card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.swipe-track {
  position: relative;
  height: 54px;
  background: var(--surface-2);
  border-radius: 27px;
  overflow: hidden;
  margin-bottom: 14px;
  user-select: none;
  touch-action: none;
}

.swipe-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  pointer-events: none;
  border-radius: 27px;
  transition: background .15s;
}

.swipe-track-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .5px;
  text-transform: uppercase;
  pointer-events: none;
}

.swipe-knob {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 48px;
  height: 48px;
  background: var(--accent);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  color: #fff;
  transition: background .2s;
}

.swipe-knob.confirmed { background: var(--success); cursor: default; }

.swipe-cancel-btn {
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 16px;
  min-height: 44px;
}

.swipe-cancel-btn:hover { color: var(--text); }

/* ─── Modal ─────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 380px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

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

.modal-title { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 0;
  transition: color .12s;
}

.modal-close:hover { color: var(--text); }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* ─── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  transition: all .2s;
  pointer-events: none;
  max-width: 320px;
}

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

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--error); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.warning { border-left: 3px solid var(--warning); }

/* ─── Utilities ─────────────────────────────────────────────────── */
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success  { background: rgba(34,197,94,.15);  color: var(--success); }
.badge-error    { background: rgba(239,68,68,.12);  color: var(--error); }
.badge-info     { background: rgba(79,142,247,.15); color: var(--accent); }
.badge-warning  { background: rgba(245,158,11,.15); color: var(--warning); }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

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

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state svg { opacity: .3; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ─── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface-3); }

/* ─── Bottom Nav (mobile only) ──────────────────────────────────── */
.bottom-nav { display: none; }

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }

  #app { flex-direction: column; }

  .main { padding-bottom: 62px; }

  .view { padding: 14px; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 58px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 200;
  }

  .bottom-nav .nav-link {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    border-radius: 0;
    width: auto;
  }

  .bottom-nav .nav-link svg { width: 20px; height: 20px; }

  .bottom-nav .nav-link span { display: block; font-size: 10px; line-height: 1; }

  .bottom-nav .nav-link.active {
    color: var(--accent);
    background: rgba(79,142,247,.1);
  }

  #break-float { bottom: 70px !important; right: 12px !important; }
}
