/* Caftaline admin — velours grenat, fil d'or (sfifa), mousseline */
:root {
  --grenat: #5B1A2B;
  --grenat-2: #7A2A3E;
  --sfifa: #C89B48;
  --sfifa-soft: #E9D3A6;
  --mousseline: #FAF7F8;
  --rose: #F1DDE1;
  --ink: #2A1A1F;
  --muted: #6F5D63;
  --line: #E4D6DA;
  --khder: #2F6B4F;
  --alerte: #A3261E;
  --card: #FFFFFF;
  --radius-s: 6px;
  --radius-m: 12px;
  --tabbar: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--mousseline); color: var(--ink);
  font: 400 16px/1.55 Figtree, system-ui, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3, .brand { font-family: Marcellus, Georgia, serif; font-weight: 400; color: var(--grenat); }
h1 { font-size: 2rem; line-height: 1.15; margin: .4rem 0 .5rem; }
h2 { font-size: 1.3rem; margin: 2rem 0 .7rem; }
h3 { font-size: 1.1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sfifa); outline-offset: 2px; }

/* brand: a little selham hood stitched in gold */
.brand { display: flex; align-items: center; gap: .55rem; font-size: 1.35rem; }
.brand-mark { width: 26px; height: 30px; border: 2px dashed var(--sfifa); border-radius: 13px 13px 3px 3px; background: var(--grenat); }
.brand-big { font-size: 2.2rem; justify-content: center; margin-bottom: .3rem; }
.brand-big .brand-mark { width: 34px; height: 40px; border-radius: 17px 17px 4px 4px; }

/* buttons */
.btn { border: 0; border-radius: var(--radius-s); padding: .7rem 1.1rem; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--grenat); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--grenat-2); }
.btn-outline { background: transparent; color: var(--grenat); box-shadow: inset 0 0 0 1.5px var(--grenat); }
.btn-outline:not(:disabled):hover { background: var(--rose); }
.btn-ghost { background: transparent; color: var(--grenat); }
.btn-ghost:hover { background: var(--rose); }
.btn-block { width: 100%; }
.btn-small { padding: .35rem .8rem; min-height: 36px; font-size: .9rem; }
.link-btn { background: none; border: 0; color: var(--grenat); font-weight: 600; padding: .4rem 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.busy { position: relative; color: transparent !important; }
.busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border: 2px solid var(--sfifa); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--grenat); }
.login-card { width: min(380px, 100%); background: var(--mousseline); border-radius: var(--radius-m); padding: 2rem 1.5rem; outline: 1.5px dashed var(--sfifa); outline-offset: -8px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 1.5rem; }
label { display: block; font-weight: 600; margin-bottom: 1rem; }
input[type=text], input[type=password], input:not([type]), input[type=number] {
  display: block; width: 100%; margin-top: .35rem; padding: .7rem .8rem; border: 1.5px solid var(--line); border-radius: var(--radius-s); background: #fff; font-weight: 400;
}
input:focus { border-color: var(--grenat); outline: none; }
.form-error { color: var(--alerte); min-height: 1.3em; font-weight: 500; }

/* layout */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1.5rem; padding: .6rem 16px; background: var(--mousseline); border-bottom: 1px solid var(--line); }
.top .link-btn { margin-left: auto; font-size: .9rem; }
.tabs { display: flex; gap: .25rem; }
.tab { background: none; border: 0; padding: .55rem .8rem; border-radius: var(--radius-s); font-weight: 600; color: var(--muted); cursor: pointer; }
.tab[aria-current=page] { color: var(--grenat); background: var(--rose); }
main { max-width: 680px; margin: 0 auto; padding: 1rem 16px 3rem; }
.panel { animation: none; }

@media (max-width: 720px) {
  .top { gap: .5rem; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding: 6px 6px env(safe-area-inset-bottom); background: var(--grenat); justify-content: space-around; }
  .tab { flex: 1; color: var(--sfifa-soft); font-size: .82rem; padding: .4rem .2rem; }
  .tab[aria-current=page] { color: #fff; background: rgba(255,255,255,.12); box-shadow: inset 0 -3px 0 var(--sfifa); }
  main { padding-bottom: calc(var(--tabbar) + 2.5rem + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.75rem; }
}

/* health */
.health { display: flex; align-items: center; gap: .6rem; font-weight: 600; padding: .8rem 1rem; border-radius: var(--radius-m); background: var(--card); border: 1px solid var(--line); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.ok .dot, .dot.ok { background: var(--khder); box-shadow: 0 0 0 4px rgba(47,107,79,.15); }
.bad .dot, .dot.bad { background: var(--alerte); box-shadow: 0 0 0 4px rgba(163,38,30,.15); }
.warn .dot, .dot.warn { background: var(--sfifa); }

/* the ribbon: the mode selector stitched like a sfifa */
.ribbon { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--grenat); border-radius: var(--radius-m); padding: 5px; gap: 5px; }
.mode { position: relative; background: transparent; border: 0; border-radius: 9px; color: var(--sfifa-soft); padding: .8rem .35rem .75rem; cursor: pointer; text-align: center; font-weight: 600; font-size: .9rem; line-height: 1.2; min-height: 64px; }
.mode small { display: block; font-weight: 400; font-size: .74rem; opacity: .85; margin-top: .2rem; }
.mode:hover { background: rgba(255,255,255,.08); }
.mode[aria-checked=true] { background: var(--mousseline); color: var(--grenat); }
.mode[aria-checked=true]::before { content: ""; position: absolute; inset: 4px; border: 1.5px dashed var(--sfifa); border-radius: 6px; pointer-events: none; }
.mode:disabled { cursor: progress; }
#modeHelp { margin-top: .7rem; }
@media (max-width: 420px) { .ribbon { grid-template-columns: repeat(2, 1fr); } }

/* services */
.services { list-style: none; margin: 0 0 1rem; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--card); }
.services li { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--line); }
.services li:first-child { border-top: 0; }
.svc-name { flex: 1; min-width: 0; }
.svc-name strong { display: block; font-weight: 600; }
.svc-name span { font-size: .85rem; color: var(--muted); }
.alert { margin-top: 1.5rem; padding: 1rem; border-radius: var(--radius-m); background: #FBEDEC; border: 1px solid #EBC3C0; }
.alert h3 { color: var(--alerte); }
.alert ul { margin: 0; padding-left: 1.1rem; font-size: .88rem; }
.alert li { margin-bottom: .3rem; word-break: break-word; }
.logbox { margin-top: 1.5rem; }
.logbox summary { cursor: pointer; font-weight: 600; color: var(--grenat); padding: .5rem 0; }
.log { margin: .5rem 0 0; padding: .9rem; max-height: 360px; overflow: auto; background: #2A1A1F; color: #F3E7EA; border-radius: var(--radius-s); font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }

/* files */
.files { list-style: none; margin: 1rem 0; padding: 0; display: grid; gap: .6rem; }
.file { width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1rem 1.1rem; cursor: pointer; display: grid; gap: .2rem; }
.file:hover { border-color: var(--grenat); }
.file strong { font-family: Marcellus, Georgia, serif; font-weight: 400; font-size: 1.2rem; color: var(--grenat); }
.file span { color: var(--muted); font-size: .9rem; }
.file em { font-style: normal; font-size: .8rem; color: var(--muted); }
.back { margin-bottom: .3rem; }
#edText { display: block; width: 100%; min-height: 55dvh; padding: 1rem; border: 1.5px solid var(--line); border-radius: var(--radius-m); background: #fff; font: 15px/1.6 Figtree, system-ui, sans-serif; resize: vertical; }
#edText:focus { outline: none; border-color: var(--grenat); }
.savebar { position: sticky; bottom: 0; display: flex; align-items: center; gap: .5rem; padding: .7rem 0; background: var(--mousseline); }
.savebar #edCount { margin-right: auto; }
.over { color: var(--alerte) !important; font-weight: 600; }
@media (max-width: 720px) { .savebar { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); } }
.history { margin-top: 1rem; padding: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); }
.history ul { list-style: none; margin: 0 0 .8rem; padding: 0; }
.history li button { width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: .6rem 0; cursor: pointer; }
.history li:first-child button { border-top: 0; }
.history li button[aria-pressed=true] { color: var(--grenat); font-weight: 600; }
.version { background: var(--mousseline); color: var(--ink); border: 1px solid var(--line); margin-bottom: .7rem; }

/* settings */
.settings { display: grid; gap: .3rem; }
.setting { display: grid; gap: .3rem; padding: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: .6rem; font-weight: 400; }
.setting-name { font-weight: 600; }
.num { display: flex; align-items: center; gap: .6rem; color: var(--muted); }
.num input { width: 7rem; margin: 0; }

/* journal */
.journal { list-style: none; margin: 1rem 0; padding: 0; border-left: 2px dashed var(--sfifa); }
.journal li { position: relative; padding: 0 0 1rem 1.1rem; }
.journal li::before { content: ""; position: absolute; left: -6px; top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--grenat); }
.journal time { display: block; font-size: .8rem; color: var(--muted); }
.journal .who { font-weight: 600; text-transform: capitalize; }
.journal .detail { font-size: .85rem; color: var(--muted); }

/* toast & dialog */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 20; max-width: calc(100% - 32px); padding: .8rem 1.1rem; border-radius: var(--radius-s); background: var(--ink); color: #fff; font-weight: 500; box-shadow: 0 6px 24px rgba(42,26,31,.25); }
.toast.err { background: var(--alerte); }
@media (max-width: 720px) { .toast { bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); } }
.confirm { border: 0; border-radius: var(--radius-m); padding: 1.4rem; max-width: min(420px, calc(100% - 32px)); box-shadow: 0 10px 40px rgba(42,26,31,.3); }
.confirm::backdrop { background: rgba(42,26,31,.45); }
.confirm-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

@media (prefers-reduced-motion: reduce) { .busy::after { animation-duration: 2s; } }
