@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=Syne:wght@400;500;600;700;800&display=swap');

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

:root {
  --radius:    10px;
  --radius-lg: 16px;
  --font-head: 'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

body[data-theme="dark"] {
  --bg:        #0a0a0a;
  --bg2:       #111111;
  --bg3:       #1a1a1a;
  --bg4:       #222222;
  --border:    #2a2a2a;
  --border2:   #333333;
  --text:      #f0ede8;
  --text2:     #888880;
  --text3:     #555550;
  --accent:    #c8f060;
  --accent2:   #a8d040;
  --red:       #f06060;
  --red2:      #c04040;
  --amber:     #f0b040;
}

body[data-theme="light"] {
  --bg:        #f5f4f0;
  --bg2:       #ffffff;
  --bg3:       #efefeb;
  --bg4:       #e5e4e0;
  --border:    #e0dfd8;
  --border2:   #d0cfc8;
  --text:      #1a1a1a;
  --text2:     #666660;
  --text3:     #999990;
  --accent:    #4a7c00;
  --accent2:   #3a6200;
  --red:       #cc3333;
  --red2:      #aa2222;
  --amber:     #b07800;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 400;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Noise texture overlay ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 9999;
}

/* ── Layout ── */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.menu-toggle {
  /* position: fixed; */
  top: 16px;
  left: 16px;
  z-index: 1000;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
}

.menu-toggle:hover {
  background: var(--bg3);
}

/* Drawer overlay */
.drawer-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.drawer-overlay.active {
  opacity: 1;
}

.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 32px 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.drawer-close {
  /* display: none; */
  background: none;
  border: 1px solid var(--border);
  font-size: 24px;
  cursor: pointer;
  color: var(--bg2);
  width: 32px; 
  height: 32px;
  line-height: 1;
  position: absolute;
  top: 24px;
  right: 24px;
  border-radius: 50%;
}

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

.sidebar-logo {
  padding: 0 24px 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

header {
  display: none;
  align-items: center;
  gap: 15px;
  padding: 24px 20px 0;
}

header .logo-mark,
.sidebar-logo .logo-mark {
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
  line-height: 1;
}

header .logo-sub,
.sidebar-logo .logo-sub {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 24px;
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.3px;
  transition: color 0.15s, background 0.15s;
  position: relative;
}

.nav-item:hover { color: var(--text); background: var(--bg3); }

.nav-item.active {
  color: var(--accent);
  background: rgba(200, 240, 96, 0.06);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-bottom {
  margin-top: auto;
  padding: 24px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text2);
}

.user-name {
  line-height: normal;
  word-break: break-all;
  max-width: 100%;
}

.user-avatar {
  width: 30px; height: 30px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  color: var(--accent);
  font-family: var(--font-head);
  font-weight: 700;
  flex-shrink: 0;
}

.main-content {
  padding: 48px 56px;
  max-width: 900px;
}

/* ── Page headers ── */
.page-header { margin-bottom: 40px; }
.page-title {
  font-family: var(--font-head);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
  margin-bottom: 6px;
}
.page-subtitle { font-size: 13px; color: var(--text2); }

/* ── Cards ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.card-sm { padding: 20px 24px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg2);
}
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }

.btn-danger {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
}
.btn-danger:hover { background: rgba(240, 96, 96, 0.1); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
}
.btn-ghost:hover { border-color: var(--text3); color: var(--text); }

.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-lg { padding: 13px 28px; font-size: 14px; }
.btn-block { width: 100%; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text2);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text3); }

textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Alert ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 20px;
  display: none;
}
.alert.show { display: block; }
.alert-err  { background: rgba(240,96,96,0.1); border: 1px solid rgba(240,96,96,0.3); color: var(--red); }
.alert-ok   { background: rgba(200,240,96,0.1); border: 1px solid rgba(200,240,96,0.3); color: var(--accent); }

/* ── Stat tiles ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-tile {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text3);
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--font-head);
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -1.5px;
}

.stat-value.green { color: var(--accent); }
.stat-value.red   { color: var(--red); }
.stat-value.amber { color: var(--amber); }

.stat-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

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

.cal-month {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.cal-nav {
  display: flex;
  gap: 8px;
}

.cal-nav-btn {
  width: 32px; height: 32px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text2);
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.cal-nav-btn:hover { border-color: var(--text3); color: var(--text); }

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

.cal-day-label {
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text3);
  padding-bottom: 10px;
}

.cal-day {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  position: relative;
  background: var(--bg3);
  color: var(--text2);
  user-select: none;
}

.cal-day:hover:not(.cal-empty):not(.cal-future) {
  border-color: var(--border2);
  color: var(--text);
  transform: scale(1.05);
}

.cal-day.cal-empty   { background: transparent; cursor: default; border: none; }
.cal-day.cal-future  { opacity: 0.25; cursor: not-allowed; }

.cal-day.cal-today {
  border-color: var(--text3);
  color: var(--text);
}

.cal-day.logged-clean {
  background: rgba(200,240,96,0.12);
  border-color: rgba(200,240,96,0.3);
  color: var(--accent);
}

.cal-day.logged-relapse {
  background: rgba(240,96,96,0.12);
  border-color: rgba(240,96,96,0.3);
  color: var(--red);
}

.cal-day .day-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  margin-top: 3px;
  flex-shrink: 0;
}

.logged-clean  .day-dot { background: var(--accent); }
.logged-relapse .day-dot { background: var(--red); }
.cal-day:not(.logged-clean):not(.logged-relapse) .day-dot { display: none; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 15px;
  width: 100%;
  max-width: 420px;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-title {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.modal-date {
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 24px;
  font-family: var(--font-mono);
}

.result-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.result-btn {
  padding: 20px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border2);
  background: var(--bg3);
  color: var(--text2);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.result-btn:hover { color: var(--text); border-color: var(--text3); }

.result-btn.selected-clean {
  background: rgba(200,240,96,0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.result-btn.selected-relapse {
  background: rgba(240,96,96,0.1);
  border-color: var(--red);
  color: var(--red);
}

.result-btn .rb-icon { font-size: 24px; display: block; margin-bottom: 6px; }
.result-btn .rb-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }

.modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ── Auth pages ── */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-box {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  font-family: var(--font-head);
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
  margin-bottom: 8px;
}

.auth-tagline {
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 40px;
  letter-spacing: 0.5px;
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg3);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 28px;
}

.auth-tab {
  padding: 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
  font-family: var(--font-mono);
}

.auth-tab.active {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border2);
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}

/* ── Progress bar ── */
.progress-wrap {
  background: var(--bg3);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(.4,0,.2,1);
}

.progress-bar.danger { background: var(--red); }

/* ── Log list ── */
.log-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.log-item:last-child { border-bottom: none; }

.log-badge {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.log-badge.clean   { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.log-badge.relapse { background: var(--red);    box-shadow: 0 0 6px var(--red); }

.log-date { color: var(--text2); min-width: 90px; font-size: 12px; }
.log-result { font-weight: 500; }
.log-result.clean   { color: var(--accent); }
.log-result.relapse { color: var(--red); }
.log-notes { color: var(--text3); font-size: 12px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-duration { color: var(--text3); font-size: 11px; margin-left: auto; white-space: nowrap; }

/* ── Settings ── */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }

.settings-label { font-size: 13px; }
.settings-hint  { font-size: 12px; color: var(--text3); margin-top: 2px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  z-index: 9998;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  max-width: 280px;
}

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

.toast.toast-ok  { border-color: rgba(200,240,96,0.4); color: var(--accent); }
.toast.toast-err { border-color: rgba(240,96,96,0.4);  color: var(--red); }

/* ── Skeleton loader ── */
.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}

@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Responsive ── */
@media (max-width: 768px) {
  header {
    display: flex;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    z-index: 1002;
    transition: left 0.3s ease;
    padding: 24px 0;
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
  }

  .drawer-header {
    display: flex;
    padding: 0 20px 20px;
    margin-bottom: 16px;
  }

  .sidebar-close  { display: block; }
  .sidebar-logo  { display: block; }
  .sidebar-bottom { display: flex; }
  .nav-item { padding: 8px 12px; font-size: 12px; border-radius: 8px; }
  .nav-item.active::before { display: block; }

  .main-content { padding: 24px 20px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .modal { max-width: calc(100vw - 15px); }

  .settings-row {
    flex-direction: column;
    justify-content: start;
    align-items: start;
    gap: 20px;
  }
}

/* ── Fade-in on load ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-up { animation: fadeUp 0.4s ease both; }
.fade-up-1 { animation-delay: 0.05s; }
.fade-up-2 { animation-delay: 0.1s; }
.fade-up-3 { animation-delay: 0.15s; }
.fade-up-4 { animation-delay: 0.2s; }
