/* KRD Systems — ops dashboard */
:root {
  --navy: #061a40; --navy-2: #0b2a5e; --blue: #005fe6; --blue-600: #004fc2; --cyan: #00a8ff;
  --steel: #a3a7ae; --slate: #5f6e85; --ink: #0d1b33; --muted: #5f6e85;
  --line: #e3e8f0; --bg: #f4f7fb; --card: #fff; --danger: #d92d3a; --ok: #0e9f6e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(6, 26, 64, .05), 0 6px 18px rgba(6, 26, 64, .06);
  --font-head: 'Montserrat', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14.5px/1.55 var(--font-body); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
img, video { max-width: 100%; display: block; }
a { color: var(--blue); text-decoration: none; }
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--navy); margin: 0; line-height: 1.2; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.eyebrow { font: 600 .72rem var(--font-head); letter-spacing: .3em; text-transform: uppercase; color: var(--blue); margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em; cursor: pointer;
  padding: .7em 1.2em; border-radius: 9px; border: 1.5px solid var(--blue); background: var(--blue); color: #fff;
  font: 600 .88rem/1 var(--font-head); letter-spacing: .01em; transition: background .15s, transform .12s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); color: var(--navy); border-color: var(--steel); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f3c5c9; }
.btn-danger:hover { background: #fdf0f1; color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: .55em .9em; font-size: .8rem; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--navy); cursor: pointer; display: inline-grid; place-items: center; font-size: 1.05rem; line-height: 1; flex: none; }
.icon-btn:hover { background: var(--bg); border-color: var(--steel); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* gate */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, var(--navy) 0 12%, transparent 12% 14%, var(--blue) 14% 18%, transparent 18%) no-repeat top left / 420px 420px,
              linear-gradient(135deg, transparent 82%, var(--blue) 82% 86%, transparent 86% 88%, var(--navy) 88%) no-repeat bottom right / 420px 420px, var(--bg); }
.gate-card { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 40px 36px; width: min(400px, 100%); display: grid; gap: 14px; justify-items: center; text-align: center; }
.gate-card h1 { font-size: 1.7rem; font-weight: 800; }
.gate-card p { margin: 0; }

/* shell */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar { background: var(--navy); color: #c9d4e8; display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: #fff; }
.brand img { background: #fff; border-radius: 8px; padding: 3px; }
.brand span { display: flex; flex-direction: column; line-height: 1.05; font-family: var(--font-head); }
.brand b { font-size: 1.05rem; letter-spacing: .04em; }
.brand small { font-size: .55rem; letter-spacing: .3em; color: #8fa1c2; margin-top: 3px; }
.tabs { display: flex; flex-direction: column; gap: 2px; overflow: auto; flex: 1; }
.tabs-label { font: 600 .66rem var(--font-head); letter-spacing: .26em; text-transform: uppercase; color: #6f83a8; margin: 16px 10px 6px; }
.tabs button { text-align: left; background: none; border: 0; color: #c9d4e8; font: 500 .9rem var(--font-body); padding: 9px 12px; border-radius: 8px; cursor: pointer; position: relative; }
.tabs button:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.tabs button[aria-current="page"] { background: rgba(0, 95, 230, .28); color: #fff; }
.tabs button[aria-current="page"]::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--cyan); }
.sidebar-foot { display: grid; gap: 8px; padding: 14px 8px 4px; border-top: 1px solid rgba(255, 255, 255, .1); }
.sidebar-foot .muted { color: #8fa1c2; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: rgba(244, 247, 251, .9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h2 { font-size: 1.15rem; font-weight: 800; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-btn { display: none; }
.status { font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.status.dirty { color: #b25e00; }
.status.dirty::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; }
.panel { padding: 28px; max-width: 980px; width: 100%; outline: none; }

/* forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; }
.card > h3 { font-size: .95rem; margin-bottom: 4px; }
.card > .hint { margin: 0 0 16px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid .full { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font: 600 .78rem var(--font-head); color: var(--navy-2); letter-spacing: .02em; }
.field small { color: var(--muted); font-size: .76rem; }
input[type="text"], input[type="url"], input[type="email"], input[type="month"], input[type="tel"], textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 95, 230, .15); }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 500; }
.toggle input { appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--steel); position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.toggle input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .18s var(--ease); }
.toggle input:checked { background: var(--blue); }
.toggle input:checked::after { transform: translateX(16px); }
.toggles { display: flex; flex-wrap: wrap; gap: 14px 28px; }

/* list editor */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.list-head p { margin: 0; }
.item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
.item-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; cursor: pointer; }
.item-head .item-title { flex: 1; font: 600 .92rem var(--font-head); color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-head .item-sub { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.item-head .chev { display: inline-block; width: 12px; transition: transform .2s; color: var(--slate); font-size: 1.1rem; }
.item.open .chev { transform: rotate(90deg); }
.item-body { padding: 4px 16px 18px; border-top: 1px solid var(--line); display: none; }
.item.open .item-body { display: block; padding-top: 16px; }
.empty { text-align: center; padding: 36px; color: var(--muted); border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fff; }
.mini-list { display: grid; gap: 8px; }
.mini-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }

/* media field */
.media-field { display: flex; gap: 12px; align-items: center; }
.media-thumb { width: 96px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg) center / cover no-repeat; overflow: hidden; flex: none; display: grid; place-items: center; color: var(--steel); font-size: .72rem; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-field .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.gallery { display: grid; gap: 10px; }
.gallery-row { display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center; background: var(--bg); border-radius: 10px; padding: 8px; }
.gallery-row .row-actions { display: flex; gap: 4px; }

/* media library */
.dropzone { border: 2px dashed #b9c6db; border-radius: var(--radius); background: #fff; padding: 28px; text-align: center; display: grid; gap: 8px; justify-items: center; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--blue); background: #eef4ff; }
.dropzone svg { width: 34px; height: 34px; stroke: var(--blue); fill: none; stroke-width: 1.8; }
.uploads { display: grid; gap: 8px; margin: 14px 0; }
.upload { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; font-size: .84rem; }
.upload-top { display: flex; justify-content: space-between; gap: 8px; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .15s; }
.upload.err { border-color: #f3c5c9; color: var(--danger); }
.upload.done .bar i { background: var(--ok); }
.media-toolbar { display: flex; gap: 10px; align-items: center; margin: 18px 0 12px; flex-wrap: wrap; }
.media-toolbar input { max-width: 280px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile-media { aspect-ratio: 4 / 3; background: var(--bg); position: relative; }
.tile-media img, .tile-media video { width: 100%; height: 100%; object-fit: cover; }
.tile-type { position: absolute; top: 6px; left: 6px; background: rgba(6, 26, 64, .8); color: #fff; font: 600 .62rem var(--font-head); letter-spacing: .1em; padding: 3px 6px; border-radius: 4px; text-transform: uppercase; }
.tile-meta { padding: 8px 10px; font-size: .76rem; display: grid; gap: 2px; }
.tile-meta b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.tile-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.tile-actions .btn { flex: 1; }
.picker .tile { cursor: pointer; transition: transform .15s, border-color .15s; }
.picker .tile:hover { border-color: var(--blue); transform: translateY(-2px); }

/* messages inbox */
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--cyan); color: var(--navy); font: 700 .7rem var(--font-head); vertical-align: 1px; }
.media-toolbar .btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.media-toolbar .push { margin-left: auto; }
.inbox { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.inbox > .empty { border: 0; border-radius: 0; }
.msg { border-bottom: 1px solid var(--line); }
.msg:last-child { border-bottom: 0; }
.msg-head { width: 100%; display: grid; grid-template-columns: 10px minmax(140px, 220px) 1fr auto; gap: 14px; align-items: center; padding: 14px 18px; background: none; border: 0; text-align: left; font: inherit; color: var(--ink); cursor: pointer; }
.msg-head:hover { background: var(--bg); }
.msg-dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.msg.unread .msg-dot { background: var(--blue); }
.msg-from { display: grid; min-width: 0; }
.msg-from b, .msg-from small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-from b { font-weight: 500; }
.msg.unread .msg-from b { font-weight: 700; color: var(--navy); }
.msg-from small { color: var(--muted); font-size: .76rem; }
.msg-preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.msg.unread .msg-preview { color: var(--ink); }
.msg-time { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.msg.open { background: #fafcff; }
.msg-body { padding: 4px 18px 18px 42px; display: grid; gap: 12px; }
.msg-body h4 { font-size: 1rem; }
.msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.6; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* history */
.history-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.history-row:last-child { border-bottom: 0; }
.history-row .when { flex: 1; }
.history-row .when b { display: block; font-weight: 600; }

/* picker dialog */
.picker { border: 0; border-radius: 16px; padding: 0; width: min(960px, calc(100% - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 30px 60px rgba(6, 26, 64, .25); background: var(--bg); }
.picker::backdrop { background: rgba(4, 18, 50, .6); }
.picker[open] { display: flex; flex-direction: column; animation: pop .2s var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
.picker-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.picker-head h3 { flex: 1; font-size: 1rem; }
.picker .uploads { margin: 12px 20px 0; }
.picker .media-grid { padding: 16px 20px 20px; overflow: auto; }

/* toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(6, 26, 64, .3); font-size: .88rem; animation: toast-in .25s var(--ease); max-width: 360px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 30; transform: translateX(-100%); transition: transform .25s var(--ease); }
  .sidebar.open { transform: none; box-shadow: 20px 0 40px rgba(6, 26, 64, .3); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .topbar h2 { font-size: 1rem; }
  .topbar-actions { width: 100%; margin-left: 0; }
  .topbar-actions .btn { flex: 1; }
  .panel { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .mini-row { grid-template-columns: 1fr auto; }
  .mini-row > :nth-child(2) { grid-column: 1; }
  .gallery-row { grid-template-columns: 72px 1fr; }
  .msg-head { grid-template-columns: 10px 1fr auto; }
  .msg-preview { grid-column: 2 / -1; }
  .msg-body { padding-left: 18px; }
  .gallery-row .row-actions { grid-column: 1 / -1; justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
