@import url("https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=IBM+Plex+Mono:wght@400;500&display=swap");

@font-face {
  font-family: "KIdDOS";
  src: url("../fonts/KIdDOS-Regular.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}

:root {
  --bg: #0f1419;
  --bg2: #171d26;
  --bg3: #1f2733;
  --line: #2a3444;
  --text: #e7ecf3;
  --muted: #8a96a8;
  --dim: #5a677a;
  --accent: #3db8a0;
  --accent-dim: rgba(61, 184, 160, 0.14);
  --accent-hover: #4fd0b6;
  --warn: #e0a84a;
  --warn-dim: rgba(224, 168, 74, 0.14);
  --danger: #e06a5c;
  --danger-dim: rgba(224, 106, 92, 0.14);
  --ok: #4cbf7a;
  --ok-dim: rgba(76, 191, 122, 0.14);
  --info: #5a9fd4;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 70% 45% at 10% -10%, rgba(61, 184, 160, 0.09), transparent 50%),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(90, 159, 212, 0.05), transparent 45%);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.app { display: flex; min-height: 100vh; }
.side {
  width: 220px; flex-shrink: 0; background: var(--bg2);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 20;
}
.brand {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .4rem; text-align: center;
  padding: 1rem 1rem .9rem; border-bottom: 1px solid var(--line);
}
.brand-logo {
  display: block; width: auto; max-width: 168px; height: auto;
  margin: 0 auto; object-fit: contain;
}
.brand-name {
  font-family: "KIdDOS", sans-serif;
  font-weight: normal;
  font-size: 1.7rem;
  line-height: 1;
  color: #fff;
  text-align: center;
  text-transform: none;
  letter-spacing: normal;
}
.nav { flex: 1; padding: .75rem .55rem; overflow: auto; }
.nav a {
  display: block; padding: .5rem .7rem; border-radius: 7px;
  color: var(--muted); font-weight: 500; margin-bottom: .15rem;
}
.nav a:hover { background: var(--bg3); color: var(--text); }
.nav a.on { background: var(--accent-dim); color: var(--accent); }
.side-foot {
  padding: .85rem; border-top: 1px solid var(--line);
  font-size: .78rem; color: var(--dim);
}
.main { flex: 1; margin-left: 220px; min-width: 0; }
.top {
  height: 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 25, .88); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.top h1 { font-size: 1.02rem; font-weight: 600; }
.content { padding: 1.2rem 1.25rem 2.5rem; }

.metrics {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem; margin-bottom: 1.2rem;
}
.metric {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem;
}
.metric .l { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.metric .v { font-family: var(--mono); font-size: 1.45rem; font-weight: 500; }
.metric .v.a { color: var(--accent); }
.metric .v.w { color: var(--warn); }
.metric .v.d { color: var(--danger); }

.grid-2 {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.1rem; align-items: start;
}
.grid-2 > .panel { margin-bottom: 0; }
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 1.1rem;
}
.panel-h {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; padding: .8rem 1rem; border-bottom: 1px solid var(--line);
}
.panel-h h2 { font-size: .92rem; font-weight: 600; }
.panel-b { padding: 1rem; }
.panel-b.flush { padding: 0; }

.panel.collapsible > .panel-h {
  cursor: pointer; user-select: none;
}
.panel.collapsible > .panel-h:hover { background: rgba(255,255,255,.02); }
.panel.collapsible .chev {
  display: inline-block; width: 1em; color: var(--dim);
  transition: transform .15s ease; transform: rotate(90deg);
}
.panel.collapsible.is-collapsed .chev { transform: rotate(0deg); }
.panel.collapsible.is-collapsed > .panel-h { border-bottom: none; }
.panel.collapsible.is-collapsed > .panel-b,
.panel.collapsible.is-collapsed > .panel-h .btn-primary { display: none; }
.panel.collapsible .panel-sum {
  font-size: .78rem; color: var(--muted); font-weight: 400; margin-left: .35rem;
}
.panel.collapsible:not(.is-collapsed) .panel-sum { display: none; }

.contact-row {
  display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start;
  padding: .65rem 0; border-bottom: 1px solid var(--line);
}
.contact-row:last-child { border-bottom: none; }
.contact-row .badge { margin-left: .35rem; vertical-align: middle; }
.contact-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.contact-section {
  font-size: .72rem; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: .04em;
  margin: .35rem 0 .25rem;
}

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.input, .select, .textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); font: inherit; padding: .45rem .65rem; outline: none; width: 100%;
}
.search { min-width: 200px; width: auto; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { min-height: 72px; resize: vertical; }
.field { margin-bottom: .75rem; }
.field label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .28rem; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-grid .full { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--bg3); color: var(--text);
  font: inherit; font-size: .84rem; font-weight: 550; padding: .42rem .75rem;
  border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06241e; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #06241e; }
.btn-ghost { background: transparent; }
.btn-warn { background: var(--warn-dim); border-color: transparent; color: var(--warn); }
.btn-danger { background: var(--danger-dim); border-color: transparent; color: var(--danger); }
.btn-sm { padding: .28rem .5rem; font-size: .76rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.data th {
  text-align: left; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--dim); padding: .6rem .9rem; border-bottom: 1px solid var(--line);
}
table.data td { padding: .65rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--bg3); }
.mono { font-family: var(--mono); font-size: .8rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }
.loading { padding: 2rem; text-align: center; color: var(--muted); }

.badge {
  display: inline-flex; font-size: .7rem; font-weight: 600;
  padding: .15rem .45rem; border-radius: 4px;
}
.badge-ok { background: var(--ok-dim); color: var(--ok); }
.badge-warn { background: var(--warn-dim); color: var(--warn); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }
.badge-info { background: rgba(90, 159, 212, .14); color: var(--info); }
.badge-neutral { background: var(--bg3); color: var(--muted); }
.badge-accent { background: var(--accent-dim); color: var(--accent); }

.backdrop {
  position: fixed; inset: 0; background: rgba(6, 10, 14, .75);
  z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 1rem; overflow: auto;
}
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  width: min(720px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal-lg { width: min(920px, 100%); }
.modal-h {
  display: flex; justify-content: space-between; align-items: center;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); font-weight: 600;
}
.modal-b { padding: 1.1rem; }
.modal-f {
  display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap;
  padding: .85rem 1.1rem; border-top: 1px solid var(--line);
}

.email-recipients { display: flex; flex-direction: column; gap: .4rem; }
.email-recipient {
  display: flex; gap: .65rem; align-items: flex-start;
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); cursor: pointer; font-size: .9rem; line-height: 1.35;
}
.email-recipient input { margin-top: .2rem; }
.email-recipient:hover { border-color: var(--muted); }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  width: min(400px, 100%); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 14px; padding: 1.75rem;
}
.login-card .brand-logo {
  display: block; width: min(220px, 72%); height: auto;
  margin: 0 auto .85rem; object-fit: contain;
}
.login-card h1 {
  font-family: "KIdDOS", sans-serif;
  font-weight: normal;
  font-size: 2rem;
  line-height: 1;
  color: #fff;
  margin-bottom: .35rem;
  text-align: center;
}
.login-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 1.35rem; text-align: center; }
.err {
  background: var(--danger-dim); color: var(--danger);
  padding: .65rem .8rem; border-radius: 7px; font-size: .85rem; margin-bottom: .85rem;
}

#toasts {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 200;
  display: flex; flex-direction: column; gap: .45rem;
}
.toast {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  padding: .65rem .9rem; font-size: .85rem; min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

.lines { display: flex; flex-direction: column; gap: .55rem; }
.line-row {
  display: grid; grid-template-columns: 1fr 1.4fr 1.1fr .55fr .7fr .7fr auto;
  gap: .4rem; align-items: start;
}
.nature-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .82rem; color: var(--muted);
  padding: .25rem .55rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg);
}
.nature-pill strong { color: var(--text); font-weight: 600; }
.line-row.line-comment {
  grid-template-columns: 1fr auto;
  align-items: start;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: .55rem .65rem;
}
.line-row.line-spacer {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 1.35rem;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: .1rem .55rem;
}
.line-actions { display: flex; flex-direction: column; gap: .2rem; align-items: center; }
.line-actions-h { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
.line-spacer-label {
  font-size: .72rem; color: var(--dim);
  letter-spacing: .04em; text-transform: uppercase;
}
.hint { font-size: .78rem; color: var(--dim); margin-top: .35rem; }

.rich-wrap {
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); overflow: hidden;
}
.rich-bar {
  display: flex; gap: .2rem; padding: .25rem .35rem;
  border-bottom: 1px solid var(--line); background: var(--bg2);
}
.rich-btn {
  border: 1px solid transparent; background: transparent; color: var(--text);
  font-family: inherit; font-size: .82rem; width: 1.85rem; height: 1.7rem;
  border-radius: 4px; cursor: pointer; line-height: 1;
}
.rich-btn:hover { background: var(--line); }
.rich-ed {
  min-height: 2.6rem; padding: .45rem .65rem;
  font-size: .88rem; line-height: 1.45; outline: none; color: var(--text);
}
.rich-ed:empty:before {
  content: attr(data-placeholder); color: var(--dim); pointer-events: none;
}
.rich-ed b, .rich-ed strong { font-weight: 700; }
.rich-ed i, .rich-ed em { font-style: italic; }
.rich-ed u { text-decoration: underline; }
.rich-view { font-size: .88rem; line-height: 1.45; color: var(--muted); }
.rich-view b, .rich-view strong { font-weight: 700; color: var(--text); }
.rich-view i, .rich-view em { font-style: italic; }
.rich-view u { text-decoration: underline; }

@media (max-width: 860px) {
  .side { display: none; }
  .main { margin-left: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .line-row { grid-template-columns: 1fr 1fr; }
  .line-row.line-comment, .line-row.line-spacer { grid-template-columns: 1fr auto; }
}
