/* Ylivieskan Vuokravarastot – prototyypin tyylit */
:root {
  /* Brändivärit (graafinen ohjeistus) */
  --dark: #343236;      /* DARK  */
  --gray: #5b6261;      /* GRAY  */
  --orange: #ee7736;    /* ORANGE */
  --sand: #ddd2cd;      /* SILVER */
  --white: #fffefd;     /* WHITE */

  --bg: #f5f3f1;
  --surface: #ffffff;
  --ink: #2b2a2e;
  --ink-soft: #6b6e72;
  --line: #e7e2dd;
  --primary: #343236;
  --primary-700: #232227;
  --accent: #ee7736;
  --accent-600: #d8631f;
  --green: #2f8f5b;
  --green-bg: #e7f3ec;
  --amber: #b7791f;
  --amber-bg: #fbf1df;
  --gray-bg: #f0ece8;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40,40,45,.05), 0 6px 20px rgba(40,40,45,.07);
  --shadow-lg: 0 10px 40px rgba(40,40,45,.16);
  --font: "Avenir Next", "Avenir", "Jost", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Libre Baskerville", "Baskerville", "Baskerville Old Face", Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
.container { max-width: 1120px; margin: 0 auto; padding: 0 24px; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--dark);
  border-bottom: 1px solid rgba(255,255,255,.10);
  position: sticky; top: 0; z-index: 50;
}
.topbar .inner { display: flex; align-items: center; justify-content: space-between; height: 70px; }
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: #fff; }
.brand .logo { height: 44px; width: auto; display: block; }
.brand .name { font-weight: 700; font-size: 15px; letter-spacing: .5px; text-transform: uppercase; line-height: 1.05; color: #fff; padding-left: 14px; border-left: 1px solid rgba(255,255,255,.2); }
.brand .name small { display: block; font-weight: 500; font-size: 11px; color: rgba(255,255,255,.6); letter-spacing: .4px; text-transform: none; margin-top: 2px; }
.nav { display: flex; gap: 8px; align-items: center; }
.nav a:not(.btn) { text-decoration: none; color: rgba(255,255,255,.82); font-weight: 600; font-size: 14.5px; padding: 8px 12px; border-radius: 8px; }
.nav a:not(.btn):hover { background: rgba(255,255,255,.12); color: #fff; }

/* Mobiilivalikon painike – JS lisää sen topbariin, CSS näyttää vain kapealla
   näytöllä (ks. responsiivisuusosio tiedoston lopussa). */
.nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin-left: 10px; flex-shrink: 0;
  background: transparent; border: 1px solid rgba(255,255,255,.24);
  border-radius: 10px; cursor: pointer; padding: 0;
}
.nav-toggle:hover { background: rgba(255,255,255,.10); }
.nav-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-toggle-bars { position: relative; display: block; width: 20px; height: 2px; background: #fff; border-radius: 2px; }
.nav-toggle-bars::before, .nav-toggle-bars::after {
  content: ""; position: absolute; left: 0; width: 20px; height: 2px;
  background: #fff; border-radius: 2px; transition: transform .18s ease;
}
.nav-toggle-bars::before { top: -6px; }
.nav-toggle-bars::after  { top: 6px; }
.nav-toggle.open .nav-toggle-bars { background: transparent; }
.nav-toggle.open .nav-toggle-bars::before { transform: translateY(6px) rotate(45deg); }
.nav-toggle.open .nav-toggle-bars::after  { transform: translateY(-6px) rotate(-45deg); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  font: inherit; font-weight: 700; font-size: 14.5px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; transition: .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-600); }
.btn-dark { background: var(--primary); color: #fff; }
.btn-dark:hover { background: var(--primary-700); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: #c7cfdd; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }

/* ---------- Hero ---------- */
.hero {
  background:
    radial-gradient(900px 420px at 88% -20%, rgba(238,119,54,.55) 0%, rgba(238,119,54,0) 60%),
    linear-gradient(160deg, var(--dark) 0%, var(--primary-700) 100%);
  color: #fff; padding: 76px 0 92px;
}
.hero h1 { font-family: var(--font-serif); font-weight: 700; font-size: 40px; line-height: 1.15; margin: 0 0 18px; max-width: 18ch; }
.hero p { font-size: 18px; color: #d7d2cd; max-width: 52ch; margin: 0 0 28px; }
.hero .cta { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 36px; margin-top: 48px; flex-wrap: wrap; }
.hero-stats .stat .n { font-size: 30px; font-weight: 800; }
.hero-stats .stat .l { font-size: 13.5px; color: #c4beb8; text-transform: uppercase; letter-spacing: .6px; }

/* ---------- Sections ---------- */
section { padding: 56px 0; }
.section-head { margin-bottom: 28px; }
.section-head h2 { font-size: 27px; margin: 0 0 6px; }
.section-head p { color: var(--ink-soft); margin: 0; font-size: 16px; }
.eyebrow { color: var(--accent); font-weight: 800; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; margin: 0 0 8px; }

/* type cards */
.types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.type-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.type-card .ic { font-size: 26px; }
.type-card h3 { margin: 12px 0 6px; font-size: 18px; }
.type-card p { color: var(--ink-soft); margin: 0 0 12px; font-size: 14.5px; }
.type-card .price { font-weight: 700; color: var(--primary); }

/* ---------- Availability ---------- */
.avail-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--ink-soft); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); display: inline-block; box-shadow: 0 0 0 4px var(--green-bg); margin-right: 8px; }
.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.unit {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative;
}
.unit .nr { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.unit .sz { font-size: 26px; font-weight: 800; margin: 2px 0 2px; }
.unit .pr { color: var(--primary); font-weight: 700; margin-bottom: 14px; }
.unit .pr span { color: var(--ink-soft); font-weight: 500; font-size: 13px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge.free { background: var(--green-bg); color: var(--green); }
.badge.rented { background: var(--gray-bg); color: var(--ink-soft); }
.badge.ei_valmis { background: var(--amber-bg); color: var(--amber); }
.empty-note { color: var(--ink-soft); padding: 30px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Footer ---------- */
footer { background: var(--primary-700); color: #c6d2e6; padding: 40px 0; margin-top: 40px; }
footer .cols { display: flex; justify-content: space-between; gap: 30px; flex-wrap: wrap; }
footer h4 { color: #fff; margin: 0 0 10px; font-size: 15px; }
footer a { color: #c6d2e6; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,22,35,.55); display: none; place-items: center; z-index: 100; padding: 20px; }
.modal-bg.open { display: grid; }
.modal { background: var(--surface); border-radius: 16px; max-width: 560px; width: 100%; box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto; }
.modal header { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; font-size: 19px; }
.modal .body { padding: 24px; }
.modal .foot { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: #fafbfd; border-radius: 0 0 16px 16px; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink-soft); line-height: 1; }

/* ---------- Forms ---------- */
label.f { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
label.f span { display: block; margin-bottom: 5px; color: var(--ink); }
input, select, textarea {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b9c9e6; border-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.note-box { background: var(--green-bg); border: 1px solid #bfe6d2; color: #146c45; padding: 12px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; }

/* ---------- Admin ---------- */
.admin-bg { background: #eef1f6; }
.admin-wrap { padding: 28px 0 60px; }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.kpi .n { font-size: 23px; font-weight: 800; margin-top: 4px; white-space: nowrap; }
.kpi .n.green { color: var(--green); }
.kpi .n.accent { color: var(--accent); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel .ph { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.panel .ph h2 { margin: 0; font-size: 18px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search { width: 230px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); background: #fafbfd; position: sticky; top: 0; }
tbody tr:hover { background: #f7f9fc; }
.table-scroll { max-height: 560px; overflow: auto; }
td .mono { font-family: "Consolas", monospace; background: var(--gray-bg); padding: 2px 7px; border-radius: 6px; font-size: 13px; }
.muted { color: var(--ink-soft); }
.row-warn td { background: #fffaf0; }
.flag { font-size: 11.5px; color: var(--danger); font-weight: 700; }

/* Nimike–arvo-parit (asiakaskortti, sopimusnäkymä, asiakasportaali) */
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; }

/* Sopimuksen esikatselu iframessa (allekirjoitussivu) */
.contract-frame { width: 100%; height: 480px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* contract preview */
.contract { font-size: 13px; line-height: 1.5; }
.contract h4 { margin: 0 0 4px; }
.contract .kv { display: grid; grid-template-columns: 150px 1fr; gap: 2px 10px; margin: 10px 0; }
.contract .kv div:nth-child(odd) { color: var(--ink-soft); }
.codebox { font-family: Consolas, monospace; font-size: 26px; font-weight: 800; letter-spacing: 4px; background: var(--primary); color: #fff; padding: 14px 18px; border-radius: 12px; text-align: center; margin: 8px 0; }

/* ---------- Tilatyypit kicker ---------- */
.types-4 { grid-template-columns: repeat(4, 1fr); }
.type-card .kicker { display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: .5px; color: var(--accent-600); background: #fbe7d6; padding: 4px 11px; border-radius: 999px; margin-bottom: 12px; }

/* ---------- Hinnasto ---------- */
.price-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 20px; }
.price-card h3 { margin: 0 0 6px; font-size: 19px; }
.price-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.price-card-head h3 { margin: 0; }
.price-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.price-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); border-bottom: 2px solid var(--line); padding: 8px 10px; }
.price-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.price-table th:not(:first-child), .price-table td:not(:first-child) { text-align: right; }
.price-table td:first-child { font-weight: 700; }
.price-table td:nth-child(2) { color: var(--primary); font-weight: 700; }
.price-table tbody tr:last-child td { border-bottom: 0; }
.price-table tbody tr:hover { background: #faf8f6; }
.hinnasto-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.size-list { list-style: none; margin: 6px 0 0; padding: 0; }
.size-list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.size-list li:last-child { border-bottom: 0; }
.size-list small { color: var(--ink-soft); font-weight: 500; }
.size-list .pp { color: var(--primary); font-weight: 700; white-space: nowrap; }
.includes { margin-top: 4px; background: var(--dark); color: #fff; border-radius: var(--radius); padding: 24px 26px; }
.includes h4 { margin: 0 0 12px; font-size: 14px; color: var(--accent); text-transform: uppercase; letter-spacing: .7px; }
.includes ul { margin: 0; padding-left: 18px; color: #e7e2dd; }
.includes li { margin-bottom: 7px; }
.includes-tag { margin: 16px 0 0; font-family: var(--font-serif); font-size: 18px; font-style: italic; color: #fff; }

/* ---------- Aluekartta ---------- */
.map-wrap { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); background: #fff; }
.map-wrap img { display: block; width: 100%; height: auto; }

/* ---------- Yhteystiedot ---------- */
.contact-co { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 24px; margin-bottom: 22px; }
.co-rows { display: flex; flex-direction: column; gap: 9px; }
.co-rows .row { display: flex; gap: 12px; font-size: 15px; align-items: baseline; }
.co-rows .lbl { color: var(--ink-soft); min-width: 92px; }
.co-rows a { color: var(--primary); font-weight: 600; text-decoration: none; }
.co-rows a:hover { text-decoration: underline; }
.co-rows .social a { color: var(--accent-600); }
.people { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.person { display: flex; gap: 18px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.person img, .person .avatar-fallback { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.person .avatar-fallback { background: var(--primary); color: #fff; place-items: center; font-weight: 800; font-size: 26px; letter-spacing: 1px; }
.p-info h3 { margin: 0 0 6px; font-size: 18px; }
.p-info a { display: block; color: var(--primary); text-decoration: none; font-size: 14px; margin-bottom: 3px; }
.p-info a:hover { text-decoration: underline; }

/* ---------- Kirjautuminen (hallinta) ---------- */
#login-overlay { position: fixed; inset: 0; z-index: 1000; background: linear-gradient(160deg, var(--dark), var(--primary-700)); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-logo { height: 46px; margin: 0 auto 22px; display: block; }
.login-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 30px; text-align: left; }
.login-card h2 { margin: 0 0 20px; font-size: 19px; text-align: center; }

/* ---------- Sopimustyypin valinta (varauslomake) ---------- */
.choice { display: grid; gap: 10px; margin-bottom: 16px; }
.choice-opt { display: flex; gap: 11px; align-items: flex-start; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; cursor: pointer; transition: .12s; }
.choice-opt:hover { border-color: #c7cfdd; }
.choice-opt input { width: auto; margin: 3px 0 0; flex-shrink: 0; }
.choice-opt span { display: flex; flex-direction: column; }
.choice-opt strong { font-size: 14.5px; }
.choice-opt small { color: var(--ink-soft); font-weight: 500; margin-top: 2px; }

/* ============================================================================
   RESPONSIIVISUUS
   ----------------------------------------------------------------------------
   Yllä olevat tyylit ovat työpöytänäkymä; tässä osiossa asettelu kavennetaan
   näytön mukaan. Katkopisteet:
       1100px  kolmen sarakkeen ruudukot kahteen
        900px  navigaatio hampurilaisvalikoksi
        720px  hallinnan taulukot korteiksi, lomakkeet yhteen sarakkeeseen
        620px  modaalit alalaidan levyksi (bottom sheet)
        560px  pienet puhelimet: tiivistetty typografia ja välistys
        400px  kapeimmat laitteet

   Osa säännöistä on rajattu .has-js-luokan alle: ne vaativat app.js:n
   (mobiilivalikko, taulukoiden data-label-otsikot). Ilman JS:ää sivu pysyy
   käytettävänä – valikko rivittyy näkyviin ja taulukot vierivät vaakasuunnassa.
   ============================================================================ */

/* Mikään ei levitä sivua vaakasuunnassa */
img, iframe, video, canvas { max-width: 100%; }

/* Ankkurilinkit eivät jää tarttuvan yläpalkin alle */
html { scroll-padding-top: 84px; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

@media (max-width: 1100px) {
  .types-4 { grid-template-columns: repeat(2, 1fr); }
  .hinnasto-grid { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Navigaatio: hampurilaisvalikko ---------- */
@media (max-width: 900px) {
  html { scroll-padding-top: 74px; }
  .topbar .inner { height: 62px; gap: 8px; }

  /* Logo kutistuu sen mukaan, paljonko valikkopainikkeelta ja mahdolliselta
     "Hallinta"-tekstiltä jää tilaa – muuten ne menevät päällekkäin kapealla
     näytöllä. min-width:0 sallii flex-itemin kutistua alle luontaisen leveyden. */
  .brand { min-width: 0; }
  .brand .logo { flex: 0 1 auto; min-width: 0; max-width: 100%; width: auto; height: auto; max-height: 32px; }
  .brand .name { flex: 0 0 auto; font-size: 12.5px; padding-left: 10px; white-space: nowrap; }

  /* Ilman JS:ää: valikko omalle rivilleen brändin alle, ja vähemmän tärkeät
     linkit piiloon. Yläpalkin korkeus joustaa, ettei valikko valu ulos. */
  .nav { flex-wrap: wrap; }
  html:not(.has-js) .topbar .inner {
    height: auto; min-height: 62px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px;
  }
  html:not(.has-js) .nav { width: 100%; justify-content: flex-start; }
  html:not(.has-js) .nav .hide-sm { display: none; }
  html:not(.has-js) .brand .logo { max-height: 30px; }

  /* JS:n kanssa: kaikki linkit avattavaan paneeliin – mitään ei katoa. */
  .has-js .nav-toggle { display: inline-flex; }
  .has-js .topbar .nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    padding: 10px 16px 16px;
    background: var(--dark); border-top: 1px solid rgba(255,255,255,.12);
    box-shadow: 0 14px 34px rgba(0,0,0,.35);
    max-height: calc(100vh - 62px); overflow-y: auto;
  }
  .has-js .topbar .nav.open { display: flex; }
  .has-js .nav a:not(.btn) { padding: 12px; font-size: 16px; }
  .has-js .nav .btn { width: 100%; margin-top: 8px; padding: 13px 16px; font-size: 15px; }
}

/* ---------- Asettelun tiivistys ---------- */
@media (max-width: 720px) {
  .container { padding: 0 18px; }
  section { padding: 40px 0; }
  .admin-wrap { padding: 20px 0 44px; }

  .hero { padding: 52px 0 60px; }
  .hero h1 { font-size: clamp(26px, 7.4vw, 34px); max-width: none; }
  .hero p { font-size: 16.5px; }
  .hero-stats { gap: 24px; margin-top: 32px; }
  .hero-stats .stat .n { font-size: 25px; }
  .section-head h2 { font-size: 23px; }

  .types, .types-4 { grid-template-columns: 1fr; }
  .hinnasto-grid { grid-template-columns: 1fr; }
  .people { grid-template-columns: 1fr; }
  .contact-co { flex-direction: column; align-items: flex-start; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi { padding: 15px; }
  .kpi .n { font-size: 21px; }
  .grid2 { grid-template-columns: 1fr; }

  /* Paneelin otsikkorivi ja haku täyteen leveyteen */
  .panel .ph { align-items: stretch; }
  .toolbar { width: 100%; }
  .search { width: 100%; }

  /* 16px estää iOS:n automaattisen zoomin kenttään fokusoitaessa */
  input, select, textarea { font-size: 16px; }

  .contract-frame { height: 62vh; min-height: 300px; }
}

/* ---------- Hallinnan taulukot → kortit ---------- */
/* Vaatii app.js:n asettamat data-label-attribuutit; ilman niitä taulukko
   jää vierimään vaakasuunnassa (.table-scroll overflow:auto). */
@media (max-width: 720px) {
  .has-js .table-scroll { max-height: none; overflow: visible; padding: 12px; }
  .has-js .table-scroll table,
  .has-js .table-scroll tbody,
  .has-js .table-scroll tr,
  .has-js .table-scroll td { display: block; width: auto; }
  .has-js .table-scroll thead { display: none; }

  .has-js .table-scroll tbody tr {
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 14px; margin-bottom: 10px;
  }
  .has-js .table-scroll tbody tr:last-child { margin-bottom: 0; }
  .has-js .table-scroll tbody tr:hover { background: var(--surface); }
  .has-js .table-scroll tbody tr.row-warn { background: #fffaf0; border-color: #eddcbb; }
  .has-js .table-scroll tbody tr.row-warn td { background: transparent; }

  .has-js .table-scroll td { border: 0; padding: 5px 0; }
  .has-js .table-scroll td[data-label]:not([data-label=""]) {
    display: grid; grid-template-columns: minmax(84px, 34%) 1fr;
    gap: 12px; align-items: baseline;
    overflow-wrap: break-word;   /* pitkät sähköpostit eivät levitä korttia */
  }
  .has-js .table-scroll td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    font-size: 11.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
    color: var(--ink-soft); line-height: 1.6;
  }

  /* Nimetön sarake = toimintopainikkeet: omalle rivilleen kortin alaosaan */
  .has-js .table-scroll td:not([data-label]),
  .has-js .table-scroll td[data-label=""] {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; padding: 0;
  }
  .has-js .table-scroll td:not([data-label]) .btn,
  .has-js .table-scroll td[data-label=""] .btn { flex: 1 1 auto; justify-content: center; }
  .has-js .table-scroll td:not([data-label]):empty,
  .has-js .table-scroll td[data-label=""]:empty { display: none; margin: 0; }

  /* Monen sarakkeen yli menevä solu (esim. "Ei tuloksia.") */
  .has-js .table-scroll td[colspan] { display: block; margin: 0; padding: 6px 0; text-align: center; }
}

/* ---------- Modaalit → alalaidan levy ---------- */
@media (max-width: 620px) {
  .modal-bg { padding: 0; place-items: end center; }
  .modal {
    width: 100%; max-width: none;
    max-height: 94vh; max-height: 94dvh;
    border-radius: 16px 16px 0 0;
    display: flex; flex-direction: column; overflow: hidden;
  }
  .modal header { position: sticky; top: 0; z-index: 2; background: var(--surface); padding: 16px 18px; }
  .modal header h3 { font-size: 17px; }
  .modal .body { flex: 1 1 auto; overflow-y: auto; padding: 18px; -webkit-overflow-scrolling: touch; }
  .modal .foot { border-radius: 0; padding: 12px 18px; flex-wrap: wrap; gap: 8px; }
  .modal .foot .btn { flex: 1 1 46%; }
}

/* ---------- Kosketuslaitteet: riittävän isot kohteet ---------- */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .chip { min-height: 36px; display: inline-flex; align-items: center; }
  .x { min-width: 44px; min-height: 44px; }
  tbody tr:hover { background: transparent; }
}

/* ---------- Pienet puhelimet ---------- */
@media (max-width: 560px) {
  .container { padding: 0 16px; }
  .brand .logo { max-height: 27px; }
  .brand .name { font-size: 11.5px; padding-left: 8px; }

  /* Nimike–arvo-parit pinoon: kapealla näytöllä 180px sarake söi tilan */
  .kv, .contract .kv { grid-template-columns: 1fr; gap: 0; }
  .kv > div:nth-child(odd), .contract .kv > div:nth-child(odd) {
    font-size: 11.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
    color: var(--ink-soft); margin-top: 10px;
  }
  .kv > div:first-child, .contract .kv > div:first-child { margin-top: 0; }

  .hero .cta { flex-direction: column; align-items: stretch; }
  .hero .cta .btn { width: 100%; }
  .avail-bar { gap: 14px; }
  .filters { width: 100%; }
  .unit-grid { grid-template-columns: 1fr; }

  .price-table { font-size: 13.5px; }
  .price-table th, .price-table td { padding: 8px 6px; }
  .price-card { padding: 18px; }
  .includes { padding: 20px; }
  .size-list li { font-size: 14px; }

  .person { gap: 14px; padding: 14px 16px; }
  .person img, .person .avatar-fallback { width: 64px; height: 64px; font-size: 20px; }
  .p-info h3 { font-size: 16.5px; }

  .codebox { font-size: 21px; letter-spacing: 3px; padding: 12px 10px; }
  .login-card { padding: 22px 20px; }
  .modal .foot .btn { flex: 1 1 100%; }
  footer { padding: 32px 0; }
  footer .cols { gap: 22px; }
}

/* ---------- Kapeimmat laitteet (esim. iPhone SE 320px) ---------- */
@media (max-width: 350px) {
  .kpis { grid-template-columns: 1fr; }
  .brand .name small { display: none; }
  .hero-stats { gap: 18px; }
  /* Nimike–arvo-pari ei enää mahdu rinnakkain – pinotaan */
  .has-js .table-scroll td[data-label]:not([data-label=""]) { grid-template-columns: 1fr; gap: 0; }
}
