:root {
  --ground: #F3F5F4; --surface: #FFFFFF; --surface-2: #F7F9F8; --line: #DDE3E1; --line-soft: #E9EDEC;
  --ink: #15201F; --ink-2: #4C5A58; --ink-3: #7C8987;
  --accent: #2F6F8F; --accent-ink: #FFFFFF; --accent-soft: #E3F0F5;
  --free: #EEF6F2; --free-hover: #D4EDE0; --free-line: #B9DCC9;
  --mine: #2F6F8F; --mine-ink: #FFFFFF;
  --taken: #E6E9E8; --taken-ink: #56625F;
  --past: repeating-linear-gradient(135deg, #F0F2F1 0 6px, #E9ECEB 6px 12px);
  --error: #B3412F; --error-soft: #FBE9E5;
  --shadow: 0 16px 40px -24px rgba(20, 35, 33, .45);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0F1514; --surface: #161E1D; --surface-2: #1B2524; --line: #2A3735; --line-soft: #222D2C;
    --ink: #E9EFEE; --ink-2: #A9B7B4; --ink-3: #74827F;
    --accent: #6DB5D6; --accent-ink: #0C1A20; --accent-soft: #1A2E37;
    --free: #172521; --free-hover: #1F3A30; --free-line: #2B4A3E;
    --mine: #6DB5D6; --mine-ink: #0C1A20;
    --taken: #263130; --taken-ink: #B4C1BE;
    --past: repeating-linear-gradient(135deg, #141B1A 0 6px, #18201F 6px 12px);
    --error: #E88A78; --error-soft: #3A211C;
    --shadow: 0 16px 40px -24px rgba(0, 0, 0, .9);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); }
body { font-family: var(--font); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--ink-2); }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin: 0; }

.btn { border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font-weight: 600; background: none; transition: background .15s, border-color .15s; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: var(--line); background: var(--surface); }
.btn.ghost:hover { border-color: var(--ink-3); }
.btn.small { padding: 6px 11px; font-size: 13px; font-weight: 500; }
.btn.icon { width: 36px; height: 36px; padding: 0; font-size: 20px; line-height: 1; }
.btn.wide { width: 100%; padding: 12px; }
.btn.danger { color: var(--error); }

.field { display: flex; flex-direction: column; gap: 6px; margin: 16px 0 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input { font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--error); font-size: 13.5px; min-height: 1.4em; margin: 10px 0; }

/* Inloggning */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 26px; margin: 4px 0 20px; letter-spacing: -.01em; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; padding: 0; }
.apt-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.apt-picker label { position: relative; }
.apt-picker input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.apt-picker span { display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px 0; background: var(--surface-2); font-size: 11px; color: var(--ink-3); transition: all .15s; }
.apt-picker span b { font-size: 20px; color: var(--ink); }
.apt-picker input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.apt-picker input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Appen */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; }
.brand strong { font-size: 18px; letter-spacing: -.01em; }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.me-pill { font-weight: 600; font-size: 13.5px; padding: 6px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; align-items: start; }
.mine, .calendar { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.mine { position: sticky; top: 16px; }
.mine-head { display: flex; justify-content: space-between; align-items: baseline; }
.mine-head h2 { font-size: 17px; }
.count { font-family: var(--mono); font-size: 13px; color: var(--ink-3); }
.mine-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mine-list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); border-left: 4px solid var(--mine); }
.mine-list .when { display: flex; flex-direction: column; flex: 1 1 140px; white-space: nowrap; }
.mine-list .when b { display: block; font-size: 14px; }
.mine-list .when b::first-letter { text-transform: uppercase; }
.mine-list .when span { font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.mine-list .actions { display: flex; gap: 6px; flex-shrink: 0; margin-left: auto; }
.mine-list li.is-moving { box-shadow: 0 0 0 2px var(--accent); }
.mine-list .empty { background: var(--surface-2); border: 1px dashed var(--line); color: var(--ink-2); font-size: 13.5px; }
.rules { font-size: 12.5px; color: var(--ink-3); margin: 16px 0 0; border-top: 1px solid var(--line-soft); padding-top: 12px; }

.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cal-title { flex: 1; text-align: center; }
.cal-title h2 { font-size: 18px; }
.cal-title span { font-size: 13px; }

.day-strip { display: none; gap: 4px; margin-bottom: 12px; }
.day-strip button { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--ink-3); }
.day-strip button b { font-size: 16px; color: var(--ink); }
.day-strip button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.day-strip button[aria-selected="true"] b { color: var(--accent-ink); }
.day-strip button.today:not([aria-selected="true"]) { border-color: var(--accent); }

.grid { --row: 26px; display: grid; gap: 2px 3px; }
.grid .day-head { position: sticky; top: 0; z-index: 3; background: var(--surface); text-align: center; font-size: 12px; color: var(--ink-3); padding-bottom: 4px; grid-row: 1; align-self: end; }
.grid .day-head b { display: block; font-size: 15px; color: var(--ink); text-transform: capitalize; }
.grid .day-head.today b { color: var(--accent); }
.grid .hour { font-family: var(--mono); font-size: 11px; color: var(--ink-3); text-align: right; padding-right: 6px; line-height: 1; padding-top: 2px; }
.cell { border: 0; border-radius: 4px; padding: 0; background: var(--free); min-width: 0; }
.cell.past { background: var(--past); cursor: default; }
.cell.blocked { cursor: not-allowed; }
.cell.start { box-shadow: inset 0 0 0 1px var(--free-line); }
.cell.start:hover, .cell.preview { background: var(--free-hover); }
.cell.preview-head { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.preview-head::after { content: attr(data-label); font-family: var(--mono); font-size: 11px; color: var(--accent); font-weight: 600; }
.booking { z-index: 2; border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; justify-content: flex-start; overflow: hidden; font-size: 12.5px; pointer-events: none; }
.booking b { font-size: 13px; }
.booking span { font-family: var(--mono); font-size: 11.5px; opacity: .85; }
.booking.taken { background: var(--taken); color: var(--taken-ink); border: 1px solid var(--line); }
.booking.mine { background: var(--mine); color: var(--mine-ink); }
.booking.ended { opacity: .55; }
.now-line { z-index: 4; height: 2px; background: var(--error); align-self: start; pointer-events: none; position: relative; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--error); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw-free { background: var(--free); box-shadow: inset 0 0 0 1px var(--free-line); }
.sw-mine { background: var(--mine); }
.sw-taken { background: var(--taken); box-shadow: inset 0 0 0 1px var(--line); }

.dialog { border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(400px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 20, 20, .45); }
.dialog h3 { font-size: 18px; margin-bottom: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); max-width: calc(100vw - 32px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--error); color: #fff; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .mine { position: static; }
  .top { padding: 12px 16px; }
  .day-strip { display: flex; }
  .grid { --row: 32px; }
  .grid .day-head { display: none; }
  #today-btn { display: none; }
}
@media (max-width: 420px) {
  .who .btn.small { padding: 5px 8px; font-size: 12px; }
  .apt-picker { gap: 6px; }
}

/* Flytta pass */
.booking.movable { pointer-events: auto; cursor: grab; touch-action: none; user-select: none; transition: opacity .15s, filter .15s; }
.booking.movable:hover { filter: brightness(1.1); }
.booking.moving { outline: 2px dashed var(--accent); outline-offset: 2px; opacity: .55; pointer-events: none; }
.booking.dragging { opacity: .3; cursor: grabbing; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
.drop-ghost { z-index: 5; pointer-events: none; border-radius: 8px; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent-soft) 85%, transparent); color: var(--accent); font-family: var(--mono); font-size: 12px; font-weight: 600; padding: 6px 8px; }
.drop-ghost.bad { border-color: var(--error); background: color-mix(in srgb, var(--error-soft) 85%, transparent); color: var(--error); }
.move-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); border: 1px dashed var(--accent); font-size: 14px; scroll-margin-top: 12px; }

/* Hyresvärd */
.link-btn { display: block; margin: 16px auto 0; background: none; border: 0; color: var(--accent); font-size: 13.5px; text-decoration: underline; text-underline-offset: 3px; }
.admin-login-label { margin: 0; font-weight: 600; font-size: 15px; }
.small { font-size: 13px; }
.admin-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; min-width: 0; }
.panel h2 { font-size: 17px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.panel-head p { margin: 4px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.chips button { border: 0; background: none; border-radius: 7px; padding: 5px 10px; font-size: 13px; color: var(--ink-2); }
.chips button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 76px; align-items: center; gap: 12px; font-size: 14px; position: relative; }
.bar-row .label { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 22px; display: flex; align-items: center; border-left: 1px solid var(--line); }
.bar { height: 16px; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 0; transition: width .25s ease; }
.bar-row .value { font-family: var(--mono); font-size: 13px; color: var(--ink); text-align: right; }
.bar-row .value span { color: var(--ink-3); }
.bar-row:hover .bar { filter: brightness(1.12); }
.bar-tip { position: absolute; right: 0; bottom: calc(100% + 4px); background: var(--ink); color: var(--surface); font-size: 12.5px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; pointer-events: none; opacity: 0; transform: translateY(3px); transition: opacity .12s, transform .12s; z-index: 2; }
.bar-row:hover .bar-tip { opacity: 1; transform: none; }

.table-wrap { overflow-x: auto; margin-top: 22px; border-top: 1px solid var(--line-soft); padding-top: 6px; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.stats-table th, .stats-table td { padding: 8px 6px; text-align: right; white-space: nowrap; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table thead th { font-size: 12px; font-weight: 600; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.stats-table tbody td { border-bottom: 1px solid var(--line-soft); font-family: var(--mono); }
.stats-table tbody td:first-child, .stats-table tfoot td:first-child { font-family: var(--font); }
.stats-table tfoot td { font-weight: 600; font-family: var(--mono); }
.stats-table .short { display: none; }

.pw-admin-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pw-admin-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); font-size: 14px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin-top: 14px; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.new-password { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); }
.new-password code { font-family: var(--mono); font-size: 22px; letter-spacing: .06em; color: var(--ink); }

@media (max-width: 860px) {
  .admin-layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .bar-row { grid-template-columns: 84px minmax(0, 1fr) 64px; gap: 8px; }
  .stats-table { font-size: 12.5px; }
  .stats-table thead th { white-space: normal; vertical-align: bottom; }
  .stats-table th, .stats-table td { padding: 7px 4px; }
  .stats-table .full { display: none; }
  .stats-table .short { display: inline; }
}
