/* Maloremi owner app. Brand: navy, gold, blue. Fonts are self-hosted (Public Sans, Barlow Condensed, SIL OFL). */
@font-face { font-family: "Public Sans"; src: url(/fonts/PublicSans-Regular.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url(/fonts/PublicSans-SemiBold.woff2) format("woff2"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url(/fonts/BarlowCondensed-Bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --navy: #0f172a;
  --navy-2: #172033;
  --navy-3: #22304a;
  --blue: #59b8e8;
  --blue-deep: #0284c7;
  --gold: #f6d84a;
  --gold-deep: #8a6d00;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --line: #dbe2ea;
  --text: #0f172a;
  --muted: #5b6b80;
  --link: #036996;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .07);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a101c;
    --surface: #141d2e;
    --surface-2: #1a2539;
    --line: #26344d;
    --text: #e6edf6;
    --muted: #9aabc2;
    --link: #7cc8ef;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(24px + var(--safe-bottom));
}
.sprite { display: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand b { display: block; font: 700 21px/1 "Barlow Condensed", sans-serif; letter-spacing: .04em; text-transform: uppercase; }
.brand small { display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.bar-title { margin: 0; font: 700 22px/1.1 "Barlow Condensed", sans-serif; letter-spacing: .03em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; color: inherit; cursor: pointer;
}
.bar .icon-btn { background: rgba(255, 255, 255, .08); color: #fff; }
.bar .icon-btn:hover { background: rgba(255, 255, 255, .16); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spin svg { animation: none; } * { transition: none !important; } }

main { max-width: 1100px; margin: 0 auto; padding: 18px 14px 32px; outline: none; }

/* ---------- Home tiles ---------- */
.hello { margin: 2px 2px 16px; }
.hello h2 { margin: 0; font: 700 30px/1.05 "Barlow Condensed", sans-serif; letter-spacing: .02em; text-transform: uppercase; }
.hello p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } }
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: space-between;
  min-height: 150px; padding: 16px; border-radius: 22px;
  background: linear-gradient(150deg, var(--navy-2), var(--navy));
  color: #fff; text-decoration: none; box-shadow: var(--shadow);
  overflow: hidden; isolation: isolate;
}
.tile::after { content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; background: radial-gradient(circle, rgba(89, 184, 232, .28), transparent 70%); z-index: -1; }
.tile:active { transform: scale(.98); }
.tile .ico { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: rgba(246, 216, 74, .14); color: var(--gold); }
.tile .ico svg { width: 26px; height: 26px; }
.tile h3 { margin: 14px 0 2px; font: 700 24px/1 "Barlow Condensed", sans-serif; letter-spacing: .03em; text-transform: uppercase; }
.tile p { margin: 0; font-size: 13px; color: #c7d3e3; min-height: 1.5em; }
.tile.ok p { color: #9fe3b7; }
.badge {
  position: absolute; top: 14px; right: 14px;
  min-width: 26px; height: 26px; padding: 0 8px; border-radius: 13px;
  display: inline-grid; place-items: center;
  font-size: 13px; font-weight: 700;
  background: var(--gold); color: var(--navy);
}
.badge.red { background: var(--red); color: #fff; box-shadow: 0 0 0 4px rgba(220, 38, 38, .25); }
.tile.alert { background: linear-gradient(150deg, #4a1520, #2a0f18); }

/* ---------- Section head ---------- */
.sec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 2px 14px; }
.sec-head p { margin: 0; color: var(--muted); font-size: 13px; }
.sec-head .spacer { flex: 1; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: var(--navy); } }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1020px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
body[data-view="grid"] .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { body[data-view="grid"] .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1020px) { body[data-view="grid"] .cards { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.card {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); color: var(--text); text-decoration: none;
  border: 1px solid transparent; min-width: 0;
}
a.card, button.card { cursor: pointer; text-align: left; font: inherit; }
button.card { border: 1px solid transparent; }
a.card:hover, button.card:hover { border-color: var(--line); }
.card.is-down { border-color: rgba(220, 38, 38, .55); box-shadow: 0 0 0 3px rgba(220, 38, 38, .12), var(--shadow); }
.card-top { display: flex; align-items: flex-start; gap: 10px; }
.card-title { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.card-who { margin: 2px 0 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.card-top .pill { margin-left: auto; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.card-meta b { color: var(--text); font-weight: 600; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.kind { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--blue-deep); }
.kind.order { color: var(--gold-deep); }
@media (prefers-color-scheme: dark) { .kind { color: var(--blue); } .kind.order { color: var(--gold); } }
.thumb { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 12px; background: var(--surface-2); }
.thumb.story { aspect-ratio: 9 / 16; max-height: 320px; }
.thumb-empty { display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; padding: 12px; }

/* Grid view: small tiles */
body[data-view="grid"] .card { padding: 12px; gap: 6px; border-radius: 14px; }
body[data-view="grid"] .card-title { font-size: 14px; }
body[data-view="grid"] .card-who { font-size: 12px; }
body[data-view="grid"] .card-meta,
body[data-view="grid"] .card-actions,
body[data-view="grid"] .bars,
body[data-view="grid"] .card-note { display: none; }
body[data-view="grid"] .thumb { border-radius: 10px; }
body[data-view="grid"] .card-top { flex-direction: column; gap: 6px; }
body[data-view="grid"] .card-top .pill { margin-left: 0; }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.green { color: #15803d; background: #dcfce7; border-color: #bbf7d0; }
.pill.red { color: #b91c1c; background: #fee2e2; border-color: #fecaca; }
.pill.amber { color: #92400e; background: #fef3c7; border-color: #fde68a; }
.pill.blue { color: #075985; background: #e0f2fe; border-color: #bae6fd; }
.pill.gold { color: #6b5300; background: #fdf6cc; border-color: #f6e58d; }
@media (prefers-color-scheme: dark) {
  .pill.green { color: #86efac; background: rgba(22, 163, 74, .16); border-color: rgba(22, 163, 74, .35); }
  .pill.red { color: #fca5a5; background: rgba(220, 38, 38, .18); border-color: rgba(220, 38, 38, .4); }
  .pill.amber { color: #fcd34d; background: rgba(217, 119, 6, .18); border-color: rgba(217, 119, 6, .4); }
  .pill.blue { color: #7dd3fc; background: rgba(2, 132, 199, .18); border-color: rgba(2, 132, 199, .4); }
  .pill.gold { color: var(--gold); background: rgba(246, 216, 74, .12); border-color: rgba(246, 216, 74, .35); }
}

/* Meter bars (servers) */
.bars { display: grid; gap: 8px; }
.meter { display: grid; grid-template-columns: 42px 1fr 48px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.meter b { text-align: right; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.fill { height: 100%; border-radius: 4px; background: var(--blue-deep); width: 0; }
.fill.warn { background: var(--amber); }
.fill.hot { background: var(--red); }
.mini { display: flex; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Banners */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 14px; background: var(--surface); box-shadow: var(--shadow); }
.banner svg { width: 26px; height: 26px; }
.banner h3 { margin: 0; font-size: 16px; }
.banner p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.banner.ok svg { color: var(--green); }
.banner.bad { background: #fff1f2; border: 1px solid #fecaca; }
.banner.bad svg { color: var(--red); }
@media (prefers-color-scheme: dark) { .banner.bad { background: rgba(220, 38, 38, .12); border-color: rgba(220, 38, 38, .35); } }
.empty, .error-box { padding: 28px 16px; text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.error-box { color: var(--text); }
.error-box p { margin: 6px 0 14px; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 15px; text-decoration: none;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--blue-deep); border-color: var(--blue-deep); } }

/* Shortcuts */
.group-title { margin: 18px 4px 10px; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.group-title:first-child { margin-top: 0; }
.link-card { flex-direction: row; align-items: center; }
.link-card .ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--navy); color: var(--gold); flex: none; }
.link-card .card-who { font-size: 12px; }
.link-card .out { margin-left: auto; color: var(--muted); }
body[data-view="grid"] .link-card { flex-direction: column; align-items: flex-start; }
body[data-view="grid"] .link-card .out { display: none; }

/* Forms */
.form-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.form-card h2 { margin: 0 0 4px; font: 700 22px/1.1 "Barlow Condensed", sans-serif; letter-spacing: .03em; text-transform: uppercase; }
.form-card > p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.field { display: grid; gap: 6px; margin: 12px 0; }
.field label { font-size: 14px; font-weight: 600; }
.field small { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 16px;
}
textarea.input { min-height: 140px; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 13px; }
.saved { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--green); }
.saved svg { width: 15px; height: 15px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sc-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
@media (min-width: 720px) { .sc-row { grid-template-columns: 140px 1fr 2fr auto; align-items: center; } }
.msg { margin: 8px 0 0; font-size: 14px; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

/* Login */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { display: block; width: 220px; max-width: 70%; margin: 0 auto 20px; }
.logo-dark { display: none !important; }
@media (prefers-color-scheme: dark) { .logo-light { display: none !important; } .logo-dark { display: block !important; } }
.login .form-card { padding: 22px; }
body.signed-out .bar { display: none; }

/* Sheet (dialog) */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(5, 10, 20, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: var(--surface); color: var(--text);
  border-radius: 22px 22px 0 0; padding: 6px 18px calc(18px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .3);
}
@media (min-width: 720px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; } }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; gap: 8px; padding: 10px 0; background: var(--surface); z-index: 1; }
.sheet-head h2 { margin: 0; font: 700 22px/1.1 "Barlow Condensed", sans-serif; letter-spacing: .03em; text-transform: uppercase; }
.sheet-head .icon-btn { margin-left: auto; background: var(--surface-2); }
.preview-img { width: 100%; border-radius: 14px; background: var(--surface-2); }
.caption { white-space: pre-wrap; font-size: 15px; background: var(--surface-2); border-radius: 12px; padding: 12px; overflow-wrap: anywhere; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60;
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 14px;
  background: var(--navy); color: #fff; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); font-size: 14px;
}
.toast.err { background: #7f1d1d; }

.foot { margin: 28px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.noscript { padding: 20px; text-align: center; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
