/* Towly – Markendesign angelehnt an demo.loud-light.de (Rail Safety Campus / recksport).
   Bordeaux-Primär, Gold-Akzent, warmer Creme-Hintergrund, Outfit + Lato. */
:root {
  --bg: #fffdfa;
  --card: #ffffff;
  --ink: #171411;
  --ink-2: #2a2119;
  --muted: #534a42;
  --line: #e7e2dc;
  --cream: #f5ecea;
  --cream-2: #eeebdc;

  --primary: #991b2b;     /* bordeaux */
  --primary-d: #7c1422;
  --primary-2: #ac1f47;
  --link: #991b2b;
  --gold: #e8a33d;
  --gold-soft: #fff7e6;
  --btn-fg: #fff;

  /* funktionale Status-Farben: leer=grün, belegt=blau, orange, rot */
  --free: #1f8a4c;   --free-bg: #e6f4ec;   --free-bd: #a7dcb8;
  --normal: #2c7a91; --normal-bg: #e4f0f3; --normal-bd: #a9cfd9;
  --orange: #c07a12; --orange-bg: #fbeccd; --orange-bd: #f0cf8f;
  --red: #c5283d;    --red-bg: #fbe7e9;    --red-bd: #eeb1b8;
  /* positive/green accents (independent of the 'free' status colour) */
  --ok: #1f8a4c;     --ok-bg: #e6f4ec;     --ok-bd: #a7dcb8;

  --radius: 14px;
  --radius-sm: 10px;
  --pill: 999px;
  --shadow: 0 6px 18px rgba(23,20,17,.07), 0 2px 6px rgba(23,20,17,.05);
  --shadow-sm: 0 1px 2px rgba(23,20,17,.05), 0 2px 8px rgba(23,20,17,.05);
  --shadow-lg: 0 24px 60px rgba(23,20,17,.12), 0 8px 20px rgba(23,20,17,.07);

  --font-display: 'Outfit', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Lato', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px; line-height: 1.5;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.01em; color: var(--ink); }
h1 { font-size: 1.6rem; margin: 0; font-weight: 700; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mt { margin-top: 1rem; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  background: linear-gradient(100deg, var(--primary-d), var(--primary));
  color: #fff; padding: .7rem 1.4rem;
  box-shadow: var(--shadow-sm);
}
.topbar a { color: #fff; }
.brand a { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; letter-spacing: -.02em; }
.brand .subtitle { display: block; font-size: .72rem; color: #f0d8c9; font-family: var(--font-body); letter-spacing: 0; }
.logo { font-size: 1.15rem; }
.mainnav { display: flex; gap: 1.2rem; margin-left: 1rem; }
.mainnav a { color: #f1ddd3; font-weight: 600; font-family: var(--font-display); font-size: .95rem; padding-bottom: 2px; border-bottom: 2px solid transparent; }
.mainnav a:hover { color: #fff; text-decoration: none; border-bottom-color: var(--gold); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .9rem; font-size: .85rem; }
.userbox .who { color: #f0d8c9; }
.inline { display: inline; }
.linkbtn { background: none; border: 0; color: var(--link); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.linkbtn-danger { color: var(--red); }
/* In the dark topbar the link buttons must stay white. */
.topbar .linkbtn { color: #fff; }

.content { max-width: 1180px; margin: 1.4rem auto; padding: 0 1.4rem; }

/* Messages */
.messages { margin-bottom: 1rem; display: grid; gap: .5rem; }
.msg { padding: .65rem .9rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow-sm); }
.msg-success { background: var(--ok-bg); border-color: var(--ok-bd); }
.msg-error { background: var(--red-bg); border-color: var(--red-bd); }
.msg-warning { background: var(--orange-bg); border-color: var(--orange-bd); }

/* Cards & headings */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1.2rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.dash-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.dash-head .actions { margin-left: auto; display: flex; gap: .5rem; }
.dash-search { display: flex; gap: .4rem; margin-left: auto; }
.dash-search input { width: 15rem; max-width: 48vw; }
@keyframes tileflash { 0% { box-shadow: 0 0 0 0 rgba(232,163,61,.95); } 100% { box-shadow: 0 0 0 10px rgba(232,163,61,0); } }
.tile-flash { animation: tileflash 1.3s ease-out 2; border-color: var(--gold) !important; }

/* Buttons */
.btn { display: inline-block; background: var(--card); border: 1px solid var(--line); color: var(--ink); padding: .5rem .9rem; border-radius: var(--pill); cursor: pointer; font: inherit; font-weight: 600; font-family: var(--font-display); transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--cream); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.95); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }

/* Dashboard layout */
.dash-grid { display: grid; grid-template-columns: 2.2fr 1fr; gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

.legend { display: flex; gap: .5rem; flex-wrap: wrap; }
.lg { padding: .28rem .65rem; border-radius: var(--pill); font-size: .8rem; font-weight: 700; font-family: var(--font-display); border: 1px solid var(--line); }
.lg-free { background: var(--free-bg); color: var(--free); border-color: var(--free-bd); }
.lg-normal { background: var(--normal-bg); color: var(--normal); border-color: var(--normal-bd); }
.lg-orange { background: var(--orange-bg); color: var(--orange); border-color: var(--orange-bd); }
.lg-red { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }

/* Shelves */
.shelves-col { display: grid; gap: 1.1rem; }
.shelf-card .card-head { margin-bottom: .7rem; }
.shelf-scroll { overflow-x: auto; }
.shelfgrid { display: grid; grid-template-columns: 1.8rem repeat(var(--cols), minmax(48px, 1fr)); gap: 6px; min-width: min-content; }
.gcorner { }
.gcolhead { text-align: center; font-weight: 700; color: var(--muted); font-family: var(--font-display); }
.growhead { display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); font-family: var(--font-display); }
.gcell { display: flex; min-height: 50px; }
.gcell > * { flex: 1; }
.tilewrap { position: relative; display: flex; flex: 1; min-width: 0; height: 100%; }
.tilewrap > .tile { flex: 1; }
.tile-menu { position: absolute; top: 2px; right: 2px; width: 18px; height: 16px; padding: 0; line-height: 14px; font-size: .8rem; font-weight: 700; border: 1px solid var(--line); background: rgba(255,255,255,.82); border-radius: 5px; cursor: pointer; color: var(--ink); z-index: 3; }
.tile-menu:hover { background: var(--card); border-color: var(--primary); }
.subcell { display: grid; gap: 3px; width: 100%; height: 100%; }
.subcell-v { grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); }
.subcell-h { grid-template-rows: repeat(var(--n, 2), minmax(0, 1fr)); }
.subcell-quad { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.subcell .tile { min-height: 22px; aspect-ratio: auto; }
.subcell .tile-code { font-size: .66rem; }

/* Tile camera indicator */
.tile-cam { position: absolute; bottom: 1px; left: 2px; font-size: .62rem; line-height: 1; opacity: .85; }
/* Towel colour swatch */
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); vertical-align: middle; margin-right: .35rem; }
.colorpick { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.colorpick input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); cursor: pointer; }
.colorpick input[type=text] { flex: 1; min-width: 8rem; width: auto; }
.tile-towel { position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); box-shadow: 0 0 0 1px rgba(255,255,255,.5); }

/* Slot photos */
.photo-add { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .9rem; }
.photo-add input[type=text] { flex: 1; min-width: 12rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem; }
.photo { margin: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--cream); }
.photo img { width: 100%; height: 130px; object-fit: cover; display: block; cursor: zoom-in; }
.photo figcaption { display: flex; flex-direction: column; gap: .15rem; padding: .4rem .5rem; }
.photo-cap { font-size: .82rem; }

/* Avatars (therapists) */
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; background: var(--cream-2); color: var(--muted); font-weight: 700; font-family: var(--font-display); font-size: .78rem; border: 1px solid var(--line); vertical-align: middle; }
.avatar-sm { width: 24px; height: 24px; font-size: .66rem; }
.avatar-lg { width: 76px; height: 76px; font-size: 1.5rem; }
.therapist-current { margin-bottom: 1rem; }
.therapist-cell { display: inline-flex; align-items: center; gap: .4rem; }
.subcell-lg { grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; max-width: 360px; }
.subcell-lg .tile { min-height: 56px; aspect-ratio: 1/1; }
.tile-missing { background: repeating-linear-gradient(45deg, #f1ece6, #f1ece6 4px, #e7ded3 4px, #e7ded3 8px); border-color: var(--line); color: var(--muted); }
.empty-state { text-align: center; padding: 2rem; }
.tile {
  aspect-ratio: 1 / 1; border-radius: var(--radius-sm); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--ink); padding: 2px; min-height: 48px;
  transition: transform .06s ease, box-shadow .06s ease;
}
.tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); }
.tile-code { font-weight: 700; font-size: .8rem; font-family: var(--font-display); }
.tile-name { font-size: .68rem; line-height: 1.05; overflow: hidden; max-width: 100%; }
.tile-free   { background: var(--free-bg);   border-color: var(--free-bd); }
.tile-normal { background: var(--normal-bg); border-color: var(--normal-bd); }
.tile-orange { background: var(--orange-bg); border-color: var(--orange-bd); }
.tile-red    { background: var(--red-bg);    border-color: var(--red-bd); }

/* Side lists */
.dash-side .badge { background: var(--cream-2); color: var(--ink-2); border-radius: var(--pill); padding: 0 .55rem; font-size: .75rem; font-weight: 700; font-family: var(--font-display); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.list li { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }
.freecodes { display: flex; flex-wrap: wrap; gap: .3rem; }
.freecode { display: inline-block; background: var(--free-bg); color: var(--free); padding: .12rem .5rem; border-radius: var(--radius-sm); font-weight: 700; font-size: .82rem; font-family: var(--font-display); border: 1px solid var(--free-bd); }

/* Notifications */
.bell { position: relative; font-size: 1.2rem; text-decoration: none; }
.bell:hover { text-decoration: none; }
.bell-badge { position: absolute; top: -6px; right: -8px; background: var(--gold); color: #3a2400; font-size: .68rem; font-weight: 800; line-height: 1; padding: .12rem .32rem; border-radius: var(--pill); border: 1px solid rgba(0,0,0,.1); }
.notif-banner { display: block; background: var(--gold-soft); border: 1px solid var(--gold); color: #7a4d05; padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 600; box-shadow: var(--shadow-sm); }
.notif-banner:hover { text-decoration: none; filter: brightness(.99); }
.banner-danger { background: var(--red-bg); border-color: var(--red-bd); color: var(--red); }

/* Appointment reminder toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1100; display: flex; flex-direction: column; gap: .5rem; max-width: 360px; }
.toast { background: var(--card); color: var(--ink); border: 1px solid var(--gold); border-left: 4px solid var(--gold); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: .6rem .8rem; display: flex; gap: .6rem; align-items: flex-start; font-size: .9rem; }
.toast-x { background: none; border: 0; font-size: 1.15rem; line-height: 1; cursor: pointer; color: var(--muted); margin-left: auto; }
.toast-fade { opacity: 0; transition: opacity .55s ease; }
.toast-last { border-color: var(--red); border-left-color: var(--red); }
.toast-last-tag { color: var(--red); }

/* Slot action modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(23,20,17,.45); }
.modal-box { position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 1.2rem 1.3rem; min-width: 300px; max-width: 92vw; }
.modal-x { position: absolute; top: .4rem; right: .6rem; background: none; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }
#sm-body { display: flex; flex-direction: column; gap: .6rem; margin-top: .8rem; }
#sm-body .btn { align-self: flex-start; }
.sm-form { display: flex; }
.sm-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }

/* Notes */
.note-add { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .8rem; }
.note-add textarea { width: 100%; }
.note-add button { align-self: flex-start; }
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.note { background: var(--gold-soft); border: 1px solid var(--cream-2); border-radius: var(--radius-sm); padding: .5rem .65rem; }
.note-text { white-space: pre-wrap; }
.note-meta { display: flex; align-items: center; gap: .6rem; margin-top: .3rem; font-size: .76rem; color: var(--muted); }
.note-empty { color: var(--muted); list-style: none; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-family: var(--font-display); }
.is-cancelled td { text-decoration: line-through; color: var(--muted); }
.is-past td { opacity: .55; }
.chip { display: inline-block; background: var(--cream-2); padding: .12rem .55rem; border-radius: var(--pill); font-size: .8rem; font-weight: 700; font-family: var(--font-display); }
.chip-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-bd); }

/* Detail */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; align-items: start; }
@media (max-width: 800px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.bigstatus { padding: .75rem .95rem; border-radius: var(--radius-sm); font-size: 1.05rem; border: 1px solid var(--line); font-family: var(--font-display); }
.action-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .8rem 0; }
.inline-form { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }

/* Forms */
.form-card { max-width: 640px; }
.field { margin-bottom: .9rem; display: flex; flex-direction: column; gap: .25rem; }
.field-check { flex-direction: row; align-items: center; gap: .5rem; }
.field label { font-weight: 700; font-family: var(--font-display); }
.field input[type=text], .field input[type=password], .field input[type=email],
.field input[type=date], .field input[type=datetime-local], .field input[type=search],
.field input[type=number], .field textarea, .field select,
input[type=text], input[type=password], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; background: var(--card); color: var(--ink);
}
.field input:focus, input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.field-check input { width: auto; }
.err { color: var(--red); font-size: .82rem; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.search { display: flex; gap: .4rem; }
.search input { width: 16rem; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #2a1115, var(--primary-d) 60%, var(--primary)); font-family: var(--font-body); }
.login-card { background: var(--card); padding: 2.2rem; border-radius: var(--radius-lg, 24px); width: 340px; box-shadow: var(--shadow-lg); }
.login-card h1 { margin-bottom: .2rem; }
.login-card form { display: grid; gap: .8rem; margin-top: 1.2rem; }
.login-card label { display: grid; gap: .25rem; font-weight: 700; font-family: var(--font-display); }
.login-card .btn-primary { width: 100%; padding: .6rem; }

/* ============================================================
   Modern polish + Dark mode
   ============================================================ */

/* Smooth theme transition (scoped to surfaces that change color) */
body, .card, .topbar, .tile, .btn, .chip, .note, .modal-box,
input, select, textarea, .lg, .freecode { transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease; }

/* Sticky header */
.topbar { position: sticky; top: 0; z-index: 50; }

/* Theme toggle button */
.theme-toggle { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22); color: #fff; width: 32px; height: 32px; border-radius: var(--pill); cursor: pointer; font-size: .95rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: rgba(255,255,255,.26); }

/* Slightly richer focus + hover polish (light + dark) */
.btn:focus-visible, .theme-toggle:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.card { transition: box-shadow .18s ease, border-color .18s ease; }

/* ---- Dark theme ------------------------------------------------ */
:root[data-theme="dark"] {
  --bg: #17130f;
  --card: #211b16;
  --ink: #f2ece3;
  --ink-2: #e7dccd;
  --muted: #b4a695;
  --line: #392f27;
  --cream: #2a221b;
  --cream-2: #332a21;

  --primary: #b3243a;
  --primary-d: #8d1b2c;
  --primary-2: #c43450;
  --link: #ef9aa7;
  --gold: #e6b259;
  --gold-soft: #2c2210;
  --btn-fg: #fff;

  --free: #5fd999;   --free-bg: #15271d;   --free-bd: #2f5a40;
  --normal: #74c4da; --normal-bg: #13242b; --normal-bd: #2e5563;
  --orange: #efb55f; --orange-bg: #2c2310; --orange-bd: #574321;
  --red: #ef8b97;    --red-bg: #2c1518;    --red-bd: #57272e;
  --ok: #5fd999;     --ok-bg: #15271d;     --ok-bd: #2f5a40;

  --shadow: 0 8px 24px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.4);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.6);
}

:root[data-theme="dark"] body { background:
  radial-gradient(1200px 600px at 80% -10%, #221a14 0%, var(--bg) 55%) fixed; }
:root[data-theme="dark"] .btn { color: var(--ink); }
:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .btn-ok,
:root[data-theme="dark"] .btn-danger { color: #fff; }
:root[data-theme="dark"] .chip { color: var(--ink); }
:root[data-theme="dark"] .bell-badge { color: #2a1a06; }
:root[data-theme="dark"] .notif-banner { color: var(--gold); }
:root[data-theme="dark"] .tile-missing { background: repeating-linear-gradient(45deg, #241d17, #241d17 4px, #2e251d 4px, #2e251d 8px); }
:root[data-theme="dark"] .tile-menu { background: rgba(33,27,22,.85); color: var(--ink); }
:root[data-theme="dark"] .table th { color: var(--muted); }
:root[data-theme="dark"] .login-card { background: var(--card); }
:root[data-theme="dark"] .login-card .muted { color: var(--muted); }
