/* =====================================================================
 *  css/app.css  —  Patient-portal, mobil-först. Teal-brand.
 *  ===================================================================== */

:root {
       --teal-deep: #2F6E60;
       --teal:      #4A9888;
       --teal-dk:   #387A70;
       --teal-soft: #E4F0EC;
       --ink:       #23302C;
       --muted:     #6B7B75;
       --bg:        #F5F8F7;
       --surface:   #FFFFFF;
       --line:      #E1E9E6;
       --danger:    #B4453A;
       --danger-bg: #FBECEA;
       --warn:      #B07A16;
       --warn-bg:   #FBF1DD;
       --ok:        #2F7D52;
       --ok-bg:     #E4F1E9;
       --radius:    14px;
       --radius-sm: 10px;
       --shadow:    0 1px 2px rgba(35,48,44,.06), 0 6px 20px rgba(35,48,44,.05);
       --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
       --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
       margin: 0; padding: 0;
       background: var(--bg);
       color: var(--ink);
       font-family: var(--sans);
       font-size: 16px;
       line-height: 1.5;
       -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; color: var(--teal-deep); margin: 0; }

/* ---- App-skal ---- */
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
       position: sticky; top: 0; z-index: 20;
       display: flex; align-items: center; gap: 12px;
       height: 56px; padding: 0 16px;
       background: var(--teal-deep);
       box-shadow: 0 1px 10px rgba(35,48,44,.14);
}
.topbar h2 { font-size: 18px; color: #fff; }
.topbar .tb-back {
       display: inline-flex; align-items: center; justify-content: center;
       border: 0; background: none; padding: 8px; margin-left: -8px;
       color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
       border-radius: 8px; text-decoration: none;
}
.topbar .tb-back:active { background: rgba(255,255,255,.16); }
.topbar .tb-spacer { flex: 1; }
.topbar .tb-action {
       border: 0; background: none; color: #fff;
       font: inherit; font-size: 14px; cursor: pointer; padding: 8px; border-radius: 8px;
}
.topbar .tb-action:active { background: rgba(255,255,255,.16); }

.view { flex: 1; padding: 20px 16px 32px; }

/* ---- Knappar ---- */
.btn {
       display: flex; align-items: center; justify-content: center;
       width: 100%; min-height: 50px; padding: 0 18px;
       border: 0; border-radius: var(--radius-sm);
       background: var(--teal); color: #fff;
       font: inherit; font-weight: 600; font-size: 16px;
       cursor: pointer; transition: background .15s;
}
.btn:active { background: var(--teal-dk); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--teal-dk); }
.btn-ghost:active { background: var(--teal-soft); }
.btn-link {
       background: none; border: 0; color: var(--teal-dk);
       font: inherit; font-size: 14px; cursor: pointer; padding: 10px;
       width: 100%; text-align: center;
}

/* ---- Fält ---- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
       width: 100%; min-height: 50px; padding: 0 14px;
       border: 1px solid var(--line); border-radius: var(--radius-sm);
       background: var(--surface); color: var(--ink);
       font: inherit; font-size: 16px;
}
.field select { -webkit-appearance: none; appearance: none; padding-right: 34px;
       background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236B7B75' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
       background-repeat: no-repeat; background-position: right 14px center; }
       .field input:focus, .field select:focus {
              outline: none; border-color: var(--teal);
              box-shadow: 0 0 0 3px rgba(74,152,136,.20);
       }
       .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
       .field .err { color: var(--danger); font-size: 13px; margin-top: 6px; display: none; }
       .field.invalid input { border-color: var(--danger); }
       .field.invalid .err { display: block; }

       /* ---- Kort ---- */
       .card {
              background: var(--surface); border: 1px solid var(--line);
              border-radius: var(--radius); box-shadow: var(--shadow);
       }

       /* ---- Logotyp ---- */
       .brand-logo { display: block; width: 190px; max-width: 62%; height: auto; margin: 0 auto; }
       .home-logo  { display: block; width: 148px; height: auto; margin: 6px auto 22px; }

       /* ---- Auth ---- */
       .auth-hero { text-align: center; padding: 30px 0 26px; }
       .auth-hero p { color: var(--muted); margin: 16px 0 0; font-size: 15px; }

       .tabs { display: flex; gap: 6px; background: var(--teal-soft); padding: 4px; border-radius: var(--radius-sm); margin-bottom: 22px; }
       .tabs button {
              flex: 1; min-height: 40px; border: 0; border-radius: 8px;
              background: transparent; color: var(--teal-dk); font: inherit; font-weight: 600; cursor: pointer;
       }
       .tabs button.active { background: var(--surface); color: var(--teal-deep); box-shadow: var(--shadow); }

       .auth-form .btn { margin-top: 6px; }

       /* ---- Home ---- */
       .home-head { margin-bottom: 22px; }
       .home-head h1 { font-size: 24px; margin-bottom: 4px; }
       .home-head p { color: var(--muted); margin: 0; }

       .nav-card {
              display: flex; align-items: center; gap: 16px;
              width: 100%; text-align: left; text-decoration: none;
              padding: 18px; margin-bottom: 14px;
              border: 1px solid var(--line); border-radius: var(--radius);
              background: var(--surface); box-shadow: var(--shadow);
              cursor: pointer; transition: transform .1s;
       }
       .nav-card:active { transform: scale(.99); }
       .nav-card .ic {
              flex: none; width: 46px; height: 46px; border-radius: 12px;
              background: var(--teal-soft); color: var(--teal-deep);
              display: flex; align-items: center; justify-content: center;
       }
       .nav-card .ic svg { width: 24px; height: 24px; }
       .nav-card .tx { flex: 1; }
       .nav-card .tx strong { display: block; font-size: 16px; color: var(--ink); font-weight: 600; }
       .nav-card .tx span { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
       .nav-card .go { color: var(--muted); font-size: 20px; }

       /* ---- Status-pill ---- */
       .pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
       .pill.bokad      { background: var(--ok-bg); color: var(--ok); }
       .pill.preliminar { background: var(--warn-bg); color: var(--warn); }
       .pill.installd   { background: var(--danger-bg); color: var(--danger); }

       /* ---- Toast ---- */
       .toast {
              position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
              background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
              font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
              max-width: 90%; text-align: center;
       }
       .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

       /* ---- Spinner / overlay ---- */
       .overlay {
              position: fixed; inset: 0; background: rgba(245,248,247,.7);
              display: none; align-items: center; justify-content: center; z-index: 40;
       }
       .overlay.show { display: flex; }
       .spinner {
              width: 34px; height: 34px; border-radius: 50%;
              border: 3px solid var(--teal-soft); border-top-color: var(--teal);
              animation: spin .7s linear infinite;
       }
       @keyframes spin { to { transform: rotate(360deg); } }

       .muted { color: var(--muted); }
       .center { text-align: center; }

       /* ---- Clínica: rubrik ---- */
       .clinic-head { margin-bottom: 6px; }
       .clinic-head h1 { font-size: 22px; }
       .clinic-head p { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

       .section-label { font-size: 13px; color: var(--muted); font-weight: 600; margin: 24px 0 10px; }

       /* ---- Chips (tjänster) ---- */
       .chips { display: flex; flex-wrap: wrap; gap: 8px; }
       .chip {
              padding: 9px 15px; border: 1px solid var(--line); border-radius: 999px;
              background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
       }
       .chip.active { background: var(--teal); border-color: var(--teal); color: #fff; }

       /* ---- Dag-strip ---- */
       .day-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
       .day {
              flex: none; width: 58px; padding: 10px 0; border: 1px solid var(--line);
              border-radius: 12px; background: var(--surface); text-align: center; cursor: pointer;
       }
       .day.active { background: var(--teal); border-color: var(--teal); }
       .day .dow { display: block; font-size: 12px; color: var(--muted); }
       .day .num { display: block; font-size: 18px; font-weight: 600; margin-top: 2px; color: var(--ink); }
       .day.active .dow, .day.active .num { color: #fff; }

       /* ---- Tider ---- */
       .person { margin-top: 18px; }
       .person h3 { font-size: 16px; margin-bottom: 10px; }
       .slots-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
       .slot {
              padding: 12px 0; border: 1px solid var(--teal-soft); border-radius: 10px;
              background: var(--teal-soft); color: var(--teal-deep);
              font: inherit; font-weight: 600; font-size: 15px; text-align: center; cursor: pointer;
       }
       .slot:active { background: var(--teal); color: #fff; border-color: var(--teal); }
       .slot.ocupado {
              background: var(--bg); color: var(--muted); border-color: var(--line);
              cursor: default; text-decoration: line-through;
       }
       .slot.ocupado:active { background: var(--bg); color: var(--muted); }

       /* ---- Bekräftelse / kvitto ---- */
       .confirm-line { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
       .confirm-line:last-child { border-bottom: 0; }
       .confirm-line .k { color: var(--muted); }
       .confirm-line .v { font-weight: 600; text-align: right; }
       .confirm-box { padding: 4px 16px; margin-bottom: 20px; }

       .success { text-align: center; padding: 40px 0 20px; }
       .success .big {
              width: 66px; height: 66px; border-radius: 50%; margin: 0 auto 18px;
              background: var(--ok-bg); color: var(--ok);
              display: flex; align-items: center; justify-content: center; font-size: 32px;
       }
       .success h1 { font-size: 24px; margin-bottom: 8px; }
       .success p { color: var(--muted); margin: 0 auto 24px; max-width: 300px; }

       /* ---- Mis reservas ---- */
       .resv { padding: 16px; margin-bottom: 14px; }
       .resv-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
       .resv-top strong { font-size: 16px; }
       .resv-when { color: var(--muted); font-size: 14px; margin-top: 6px; }
       .resv-sub { color: var(--ink); font-size: 14px; margin-top: 4px; }
       .resv-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
       .btn-sm { width: auto; min-height: 40px; padding: 0 16px; font-size: 14px; }
       .btn-danger { background: var(--danger); }
       .btn-danger:active { background: #933; }
       .btn-outline { background: transparent; border: 1px solid var(--line); color: var(--ink); }
       .btn-outline:active { background: var(--teal-soft); }

       /* ---- Perfil ---- */
       .profile-head { text-align: center; margin-bottom: 8px; }
       .avatar-lg {
              width: 78px; height: 78px; border-radius: 50%; margin: 0 auto 12px;
              background: var(--teal-soft); color: var(--teal-deep);
              display: flex; align-items: center; justify-content: center;
              font-family: var(--serif); font-size: 34px; font-weight: 600;
       }
       .profile-head .email { color: var(--muted); font-size: 14px; }
       .profile-head .photo-note { color: var(--muted); font-size: 12px; margin-top: 6px; }
       .profile-section { margin-top: 8px; }
       .profile-section .btn { margin-top: 4px; }

       /* ---- ID-kort-ruta ---- */
       .idcard-box {
              padding: 16px; margin-bottom: 20px;
              border: 1.5px dashed var(--border-strong, #B4B2A9); border-radius: 14px;
              background: var(--surface);
       }
       .idcard-box.filled { border-style: solid; border-color: var(--line); }
       .idcard-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; }
       .idcard-ic {
              flex: none; width: 46px; height: 46px; border-radius: 10px; margin-bottom: 6px;
              background: var(--teal-soft); color: var(--teal-deep);
              display: flex; align-items: center; justify-content: center;
       }
       .idcard-ic svg { width: 26px; height: 26px; }
       .idcard-empty strong { font-size: 15px; color: var(--ink); }
       .idcard-img { display: block; width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: var(--teal-soft); }

       /* ---- Inställningslänk ---- */
       .settings-link {
              display: flex; align-items: center; justify-content: space-between;
              width: 100%; padding: 16px; margin-top: 20px;
              border: 1px solid var(--line); border-radius: 14px;
              background: var(--surface); font: inherit; font-size: 16px; color: var(--ink); cursor: pointer;
       }
       .settings-link .go { color: var(--muted); font-size: 20px; }
       .settings-link:active { background: var(--teal-soft); }

       /* ---- Modal (bottom sheet) ---- */
       .modal-overlay {
              position: fixed; inset: 0; background: rgba(35,48,44,.45);
              display: none; align-items: flex-end; justify-content: center; z-index: 60;
       }
       .modal-overlay.show { display: flex; }
       .modal {
              background: var(--surface); width: 100%; max-width: 480px;
              border-radius: 18px 18px 0 0; padding: 20px 16px 28px;
              animation: sheet-up .2s ease;
       }
       @keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
       .modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
       .modal-head h3 { font-size: 18px; }
       .modal-x { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }

       @media (prefers-reduced-motion: reduce) {
              * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
       }
