/* Studify design layer — loaded after app.css, and wins over it.
 *
 * The app's look had grown one patch at a time: pill-shaped everything, a floating sidebar card,
 * buttons that jump on hover, coloured stripes down the left edge of cards. Each was fine alone;
 * together they read as home-made. This file sets the calmer, more deliberate system every
 * screen now shares:
 *
 *   - a flush, full-height sidebar and a real top bar (with library search) on desktop
 *   - 10px corners on controls, 14px on cards; pills only for tags and toggles
 *   - buttons that darken on hover instead of lifting; hairline borders and quiet shadows
 *   - subject colour shown as a small mark, never as a thick stripe down a card's edge
 *   - tighter, heavier headings
 *
 * Tokens come first so light, paper and dark themes all pick the system up.
 */

:root {
  --canvas:       #F6F7F9;
  --surface-sunk: #F0F2F5;
  --line:         #E3E6EB;
  --line-strong:  #CFD4DC;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 2px 4px -2px rgba(16, 24, 40, .06), 0 12px 24px -6px rgba(16, 24, 40, .12);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .04);
  --sidebar-w: 248px;
  --sb-row: 38px;   /* a sidebar row's height */
  --sb-ic: 18px;    /* its icon */
  /* On a window taller than about 960px the sidebar's rows grow to fill it, and their text, icons and section
     labels grow a little with them (up to 2-3px), so a taller row never looks empty. */
  --sb-fs: clamp(14px, calc(14px + (100vh - 960px) / 120), 16px);
  --sb-gfs: clamp(12px, calc(12px + (100vh - 960px) / 160), 13.5px);
  --sb-ic-fill: clamp(var(--sb-ic), calc(var(--sb-ic) + (100vh - 960px) / 80), calc(var(--sb-ic) + 3px));
  --topbar-h: 60px;
}
/* The sidebar on other screens: narrower beside a tablet-width page (a big iPad upright or lying down, a small
   laptop), a little tighter on short windows, and wider with roomier rows on big monitors. */
@media (min-width: 900px) and (max-width: 1199px) { :root { --sidebar-w: 224px; } }
@media (min-width: 900px) and (max-height: 820px) { :root { --sb-row: 35px; } }
@media (min-width: 900px) and (max-height: 700px) { :root { --sb-row: 33px; } }
@media (min-width: 2000px) { :root { --sidebar-w: 276px; --sb-row: 44px; --sb-ic: 20px; } }
@media (min-width: 2600px) { :root { --sidebar-w: 300px; --sb-row: 46px; --sb-ic: 21px; } }
:root[data-theme="dark"], .theme-night { --shadow-card: 0 1px 2px rgba(0, 0, 0, .3); }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] { --shadow-card: 0 1px 2px rgba(0, 0, 0, .3); } }

/* ---------- type ---------- */
h1, h2, h3, .display { letter-spacing: -.022em; }
h1 { font-weight: 750; }
.content h1 { font-size: clamp(1.6rem, 1.25rem + 1vw, 2rem); }

/* ---------- buttons, icon buttons, panels ----------
   Their new base look lives in app.css's own .btn / .iconbtn / .panel rules, not here: this file
   loads last, so a base rule here would beat every later special case in app.css (the commute
   mode's big buttons, .iconbtn--sm, the phone-size .btn--sm) at equal specificity. */
.homebtn { border-radius: 8px; border-color: var(--line); }

/* Set cards: subject shown as the tag's colour and a thin top edge, not a 6px stripe. */
.acard {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  overflow: hidden;
}
.acard::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: var(--subject, var(--brand)); opacity: .9;
}
@media (hover: hover) { .acard:hover { transform: none; border-color: var(--line-strong); box-shadow: var(--shadow-2); } }
.acard--new { border: 1.5px dashed var(--line-strong); box-shadow: none; }
.acard--new::before { display: none; }
@media (hover: hover) { .acard--new:hover { box-shadow: none; } }
.acard__tag { border-radius: 6px; letter-spacing: .05em; }
.acard__title { font-weight: 650; letter-spacing: -.015em; }

/* The remaining left-edge stripes become an even hairline border. */
.tile--resume { border-left-width: 1px; }
.house-ad { border-left-width: 1px; border-color: var(--line); border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.plan-row { border-left: 1px solid var(--line); }
.plan-row.is-overdue { border-left-color: var(--retry); }
.source-opt--subject { border-left-width: 1px; }
.review-so-far__item { border-left-width: 1px; }
.review-so-far__item.is-ok { border-color: var(--line); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.review-so-far__item.is-miss { border-color: var(--line); border-color: color-mix(in srgb, var(--retry) 45%, var(--line)); }

/* ---------- inputs ---------- */
.search { border-radius: var(--r-md); }

/* ---------- desktop shell ---------- */
@media (min-width: 900px) {
  .sidebar {
    width: var(--sidebar-w); margin: 0; top: 0; height: 100vh;
    padding: 0 12px 14px;
    border: 0; border-right: 1px solid var(--line); border-radius: 0;
    background: var(--surface);
  }
  /* The logo at the top and the footer at the bottom keep their size; the list between them takes exactly the
     height that's left. On a window too short even for 28px rows, the list scrolls inside that space (a thin
     bar while the pointer is over it); the side margins let a row's glow and focus ring reach the edges. */
  .sidebar__brand, .sidebar__foot { flex-shrink: 0; }
  .sidebar__nav {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    margin-inline: -12px; padding: 2px 12px;
    scrollbar-width: thin; scrollbar-color: transparent transparent;
  }
  .sidebar__nav:hover { scrollbar-color: var(--line-strong) transparent; }
  .sidebar__brand {
    position: sticky; top: 0; z-index: 2;
    height: var(--topbar-h); margin: 0 -12px 10px; padding: 0 22px;
    font-size: 1.15rem; font-weight: 750; letter-spacing: -.02em;
    border-bottom: 1px solid var(--line); background: var(--surface);
  }
  .sidebar__brand img { width: 28px; height: 28px; }
  .sidebar__link {
    min-height: var(--sb-row); padding: 0 10px; gap: 11px;
    border-radius: 8px; font-size: calc(var(--sb-fs) * var(--fs-scale, 1)); font-weight: 500; color: var(--ink-soft);
  }
  /* The list always runs exactly from the logo down to the footer, with no empty stretch anywhere: on a tall window
     the rows, the space above each section label and the space around the divider all grow by the same share, so
     the whole menu scales up evenly instead of leaving one gap (above Klasser) or wide gaps between the sections.
     On a short window they all give a little (rows never below 28px). Only if even that can't fit does the list
     scroll. The flex-grow values follow each part's own height, which is what keeps the growth in proportion. */
  :is(.sidebar__nav, .sidebar__more) > :is(.sidebar__link, .sidebar__acc) {
    flex: 1 1 var(--sb-row); min-height: 28px;
  }
  .sidebar__link svg { width: var(--sb-ic-fill); height: var(--sb-ic-fill); stroke-width: 1.8; color: var(--ink-faint); }
  .sidebar__link:hover svg { color: var(--ink-soft); }
  .sidebar__link.is-active { background: var(--brand-tint); color: var(--brand-ink); font-weight: 600; }
  .sidebar__link.is-active svg { color: var(--brand); }
  /* Section labels read like quiet headings, not shouted caps. */
  /* A label grows with its rows and stays at the bottom of its space, right above them. */
  .sidebar__group {
    display: flex; align-items: flex-end; flex: 0.8 1 auto;
    margin: 0 10px 4px; padding-top: 16px; font-size: calc(var(--sb-gfs) * var(--fs-scale, 1)); letter-spacing: 0; font-weight: 500; text-transform: none;
  }
  .sidebar__acc { min-height: var(--sb-row); padding: 0 10px; border-radius: 8px; font-weight: 500; font-size: calc(var(--sb-fs) * var(--fs-scale, 1)); }
  .sidebar__acc svg:first-child { width: calc(var(--sb-ic-fill) - 2px); height: calc(var(--sb-ic-fill) - 2px); stroke-width: 1.8; color: var(--ink-faint); }
  .sidebar__acc-count { border-radius: 6px; }
  /* The line above Klasser: drawn in the middle of its own space, which grows like the rest. */
  .sidebar__div {
    flex: 0.55 1 21px; height: auto; min-height: 9px; margin: 0 10px; padding: 0; border: 0;
    background: linear-gradient(var(--line), var(--line)) no-repeat center / 100% 1px;
  }
  /* Contrast themes drop background images, so the line is a border there. */
  @media (forced-colors: active) { .sidebar__div { background: none; border-bottom: 1px solid CanvasText; } }
  /* The footer's band: the negative margins pull it over the sidebar's padding, to the edges and the bottom. */
  .sidebar__foot {
    position: sticky; bottom: -14px; z-index: 2; gap: 6px;
    margin: 14px -12px -14px; padding: 12px 12px 14px;
    border-top: 1px solid var(--line); background: var(--surface);
  }
  /* Two icon buttons (settings, theme) beside the streak — kept narrow so "N dagar i rad" usually fits on one line; longer labels ("Svit i fara …") wrap. */
  .sidebar__themebtn { width: 40px; }
  .sidebar__streak { gap: 8px; padding: 7px 8px 7px 6px; }
  .sidebar__streak-icon { width: 28px; height: 28px; }
  .sidebar__streak { border-radius: var(--r-md); }

  /* A real top bar: search on the left, account controls on the right, a hairline underneath. */
  .topbar {
    height: var(--topbar-h);
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .topbar__inner {
    max-width: none; height: 100%;
    justify-content: flex-start; gap: 10px;
    padding: 0 clamp(24px, 3vw, 40px);
  }
  .content { padding-top: clamp(28px, 3vw, 40px); }
}
/* Laptop and Chromebook heights: a little less air between the sections, so the rows have more of the height. */
@media (min-width: 900px) and (max-height: 820px) {
  .sidebar__brand { margin-bottom: 4px; }
  .sidebar__group { margin-bottom: 2px; padding-top: 8px; }
  .sidebar__div { flex-basis: 13px; }
  .sidebar__acc { margin-top: 6px; }
  .sidebar__foot { margin-top: 8px; padding-top: 10px; padding-bottom: 12px; }
}
@media (min-width: 900px) and (max-height: 700px) {
  .sidebar__group { padding-top: 6px; }
  .sidebar__brand { margin-bottom: 2px; }
  .sidebar__nav { padding-block: 0; }
}

/* Library search in the top bar — desktop only; phones have the library tab. */
.topsearch { display: none; }
@media (min-width: 900px) {
  .topsearch {
    position: relative;
    display: flex; align-items: center; gap: 8px;
    flex: 0 1 420px; height: 38px; padding: 0 12px;
    border: 1px solid var(--line); border-radius: var(--r-md);
    background: var(--surface-sunk); color: var(--ink-faint);
    transition: border-color var(--dur-fast), background var(--dur-fast), box-shadow var(--dur-fast);
  }
  .topsearch:focus-within { background: var(--surface); border-color: var(--brand); }
  .topsearch svg { flex: none; stroke-width: 1.8; }
  .topsearch__input {
    /* align-self: the whole 38px box takes the tap, not just the 25px line of text in its middle */
    flex: 1; align-self: stretch; min-width: 0; border: 0; outline: 0; background: transparent;
    font: inherit; font-size: calc(14px * var(--fs-scale, 1)); color: var(--ink);
  }
  /* The wrapper's :focus-within above already shows focus (border + background) —
     without this, the input itself also picks up the global :focus-visible outline
     (app.css), stacking a second, much heavier blue halo on top. */
  .topsearch__input:focus-visible { outline: none; box-shadow: none; }
  .topsearch__input::placeholder { color: var(--ink-faint); }
  .topsearch__input::-webkit-search-cancel-button { display: none; }

  /* The live suggestions dropdown — subjects/sets matching what's typed. */
  .topsearch__results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
    max-height: 360px; overflow-y: auto; padding: 6px;
    background: var(--surface); border: 1px solid var(--line-strong);
    border-radius: var(--r-md); box-shadow: var(--shadow-2);
  }
  .topsearch__row {
    width: 100%; display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border: none; border-radius: var(--r-sm);
    background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer;
  }
  .topsearch__row svg { flex: none; color: var(--ink-faint); }
  .topsearch__row.is-sel { background: var(--brand-tint); }
  .topsearch__row-text { display: flex; flex-direction: column; min-width: 0; }
  .topsearch__row-text strong { font-size: calc(14px * var(--fs-scale, 1)); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topsearch__row-text small { font-size: calc(12px * var(--fs-scale, 1)); color: var(--ink-faint); }
  .topsearch__empty { padding: 10px; font-size: calc(13px * var(--fs-scale, 1)); color: var(--ink-faint); }
}

/* ---------- mobile shell ---------- */
@media (max-width: 899.98px) {
  /* The page's own colour, opaque: the phone's status bar above it takes the same one (theme-color, the
     root's background), so bar and page are one surface. The hairline underneath still marks its edge. */
  .topbar { background: var(--canvas); backdrop-filter: none; }
  .tabbar { background: var(--canvas); backdrop-filter: none; }
  .brand { font-weight: 750; letter-spacing: -.02em; }
  .tabbar__item span { font-size: calc(12px * var(--fs-scale, 1)); font-weight: 550; }
  .tabbar__item svg { stroke-width: 1.8; }
}

/* ---------- in-app footer: one quiet line ---------- */
.sitefooter {
  padding-top: 18px; gap: 6px 18px; font-size: calc(13px * var(--fs-scale, 1));
  justify-content: flex-start;
}
.sitefooter__links { gap: 4px 18px; }
.sitefooter__links a { color: var(--ink-faint); }
.sitefooter__copy { width: auto; order: 0; margin-left: auto; font-size: calc(13px * var(--fs-scale, 1)); }
@media (max-width: 620px) { .sitefooter__copy { margin-left: 0; width: 100%; } }

/* The language button carries a flag and a code, so it keeps its own width. */
.langbtn { width: auto; padding: 0 10px; }

/* ---------- home ---------- */
.home__head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px 24px; margin-bottom: 28px;
}
.home__title { min-width: 0; }
.home__date { margin: 0 0 6px; font-size: calc(13px * var(--fs-scale, 1)); font-weight: 600; color: var(--ink-faint); letter-spacing: .01em; }
.home__date { flex-wrap: wrap; row-gap: 2px; }
.home__todaywrap { display: inline-flex; gap: 6px; white-space: nowrap; }
.home__today { font-weight: 500; }

/* Panel headings on the home page read as section titles, not bold body text. */
.home-panel { border-radius: var(--r-lg); box-shadow: var(--shadow-card); }
.home-panel__label > span:first-child { font-size: calc(15px * var(--fs-scale, 1)); font-weight: 650; letter-spacing: -.01em; }
.home-panel__label .linkbtn { font-size: calc(13.5px * var(--fs-scale, 1)); font-weight: 600; }

/* Very small phones (320px): the top bar needs 340px at its normal spacing, which made the whole page
   scroll sideways. Tighter gaps and side padding are enough to fit it; the 44px buttons stay. */
@media (max-width: 350px) {
  .topbar__inner { gap: 4px; padding-left: var(--s-2); padding-right: var(--s-2); }
  .topbar__actions { gap: 4px; }
  .topbar__inner .langbtn { padding: 0 8px; }
}
