/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ── Design tokens ───────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3347;
  --accent:    #5b8dee;
  --accent2:   #a78bfa;
  --success:   #34d399;
  --warning:   #fbbf24;
  --danger:    #f87171;
  --text:      #e8eaf0;
  --muted:     #7b82a0;
  --serif:     'DM Serif Display', Georgia, serif;
  --sans:      'DM Sans', system-ui, sans-serif;
  --radius:    12px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --bottom-nav-height: 64px;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

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

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  height: 60px;
  gap: 16px;
}
.topbar-logo {
  font-family: var(--serif);
  font-size: 1.35rem;
  color: var(--text);
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-logo .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.topbar-spacer { flex: 1; }
.topbar-user {
  font-size: .85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: .8rem;
  color: #fff;
}
.btn-logout {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .8rem;
  transition: all .18s;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-section {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  padding: 12px 12px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .9rem;
  font-weight: 400;
  transition: all .15s;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: rgba(91,141,238,.15); color: var(--accent); font-weight: 500; }

/* ── Main content ────────────────────────────────────────── */
.main {
  padding: 32px 36px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 60% 40% at 80% -10%, rgba(91,141,238,.08) 0%, transparent 60%),
    radial-gradient(ellipse 40% 30% at 0% 100%,  rgba(167,139,250,.06) 0%, transparent 60%),
    var(--bg);
}

.page-header { margin-bottom: 28px; }
.page-title {
  font-family: var(--serif);
  font-size: 2rem;
  line-height: 1.2;
  color: var(--text);
}
.page-subtitle {
  color: var(--muted);
  font-size: .9rem;
  margin-top: 4px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-sm { padding: 16px 20px; }

/* ── Stats row ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent-bar, var(--accent));
  opacity: .7;
}
.stat-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--serif);
  font-size: 1.9rem;
  line-height: 1;
  color: var(--text);
}
.stat-sub {
  font-size: .78rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Calendar ────────────────────────────────────────────── */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.cal-title {
  font-family: var(--serif);
  font-size: 1.4rem;
  flex: 1;
  text-align: center;
  text-transform: capitalize;
}
.btn-nav {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.btn-nav:hover { border-color: var(--accent); color: var(--accent); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-weekday {
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding: 6px 0;
}
.cal-day {
  min-height: 72px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  transition: all .15s;
  position: relative;
  overflow: hidden;
}
.cal-day:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(91,141,238,.15); }
.cal-day.empty { background: transparent; border-color: transparent; cursor: default; }
.cal-day.empty:hover { transform: none; box-shadow: none; }
.cal-day.today { border-color: var(--accent); }
.cal-day.today .cal-day-num { color: var(--accent); font-weight: 600; }
.cal-day.has-entry { background: rgba(91,141,238,.07); }
.cal-day.weekend .cal-day-num { color: var(--muted); }
.cal-day-num { font-size: .82rem; font-weight: 500; margin-bottom: 4px; }
.cal-day-worked { font-size: .7rem; color: var(--success); font-weight: 500; }
.cal-day-flex { font-size: .68rem; margin-top: 2px; }
.cal-day-flex.pos { color: var(--accent); }
.cal-day-flex.neg { color: var(--danger); }
.cal-day-dot {
  position: absolute;
  bottom: 6px; right: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ── Form ────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.form-control {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91,141,238,.12);
}
textarea.form-control { resize: vertical; min-height: 70px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4a7ce0; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(91,141,238,.35); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-ghost:hover { border-color: var(--text); color: var(--text); }

/* ── Table ───────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(46,51,71,.6);
  font-size: .88rem;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-plus  { background: rgba(52,211,153,.15); color: var(--success); }
.badge-minus { background: rgba(248,113,113,.15); color: var(--danger); }
.badge-zero  { background: rgba(123,130,160,.15); color: var(--muted); }

/* ── Flash messages ──────────────────────────────────────── */
.flash {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: .88rem;
  border: 1px solid;
}
.flash-success { background: rgba(52,211,153,.1);  border-color: rgba(52,211,153,.3);  color: var(--success); }
.flash-error   { background: rgba(248,113,113,.1); border-color: rgba(248,113,113,.3); color: var(--danger); }

/* ── Login page ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 70% 60% at 30% 20%, rgba(91,141,238,.12) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 90%, rgba(167,139,250,.1) 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow);
}
.login-logo { font-family: var(--serif); font-size: 2rem; text-align: center; margin-bottom: 8px; }
.login-tagline { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 32px; }
.login-card .form-group { margin-bottom: 16px; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 560px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: modal-in .2s ease;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.modal-title { font-family: var(--serif); font-size: 1.4rem; }
.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: var(--surface2);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: all .15s;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--danger); color: #fff; }

/* ── Divider ─────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ── Bottom navigation (mobil) ───────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 90;
  justify-content: space-around;
  align-items: center;
  padding: 0 8px;
}
.bottom-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  transition: all .15s;
  text-decoration: none;
}
.bottom-nav-link svg { width: 22px; height: 22px; }
.bottom-nav-link.active { color: var(--accent); }
.bottom-nav-link:active { background: var(--surface2); }

/* ── Responsiv tabell (mobil) ────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 0 24px;
}

/* ── Utility ─────────────────────────────────────────────── */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }

/* ══════════════════════════════════════════════════════════
   RESPONSIV – Tablet (max 860px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar { display: none; }
  .main {
    padding: 20px 16px;
    padding-bottom: calc(var(--bottom-nav-height) + 20px);
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .bottom-nav { display: flex; }
  .topbar { padding: 0 16px; }
  .topbar-user span { display: none; }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIV – Mobil (max 480px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 1.5rem; }
  .page-title { font-size: 1.5rem; }
  .card { padding: 16px; }

  /* Kalender – mindre celler på mobil */
  .cal-day {
    min-height: 48px;
    padding: 4px;
  }
  .cal-day-num { font-size: .75rem; }
  .cal-day-worked { font-size: .6rem; }
  .cal-day-flex { font-size: .58rem; }
  .cal-weekday { font-size: .6rem; padding: 4px 0; }
  .calendar-grid { gap: 2px; }

  /* Modal – fullskärm på mobil */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 95vh;
    border-radius: 16px 16px 0 0;
  }
  .modal-header { padding: 16px 20px; }
  .modal-body { padding: 16px 20px; }
  .modal-footer { padding: 12px 20px; }

  /* Topbar */
  .topbar { height: 52px; padding: 0 12px; }
  .topbar-logo { font-size: 1.1rem; }
  .btn-logout { display: none; }

  /* Login */
  .login-card { width: 100%; border-radius: 0; min-height: 100vh; padding: 32px 20px; }
}