:root {
  --bg: #f0f9ff;
  --surface: #ffffff;
  --ink: #0c1a28;
  --ink-soft: #4a6578;
  --navy: #0c1a28;
  --brand: #0284c7;
  --brand-bright: #7dd3fc;
  --brand-dark: #0369a1;
  --brand-glow: rgba(2, 132, 199, 0.32);
  --panel-bg: #0c4a6e;
  --panel-ink: #f0f9ff;
  --panel-muted: rgba(224, 242, 254, 0.85);
  --border: #cfe8f7;
  --shadow: 0 12px 40px rgba(12, 74, 110, 0.08);
  --header-bg: rgba(255, 255, 255, 0.92);
  --radius: 16px;
  --sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --ok: #0f766e;
  --warn: #b45309;
  --bad: #b42318;
  --info: #0369a1;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070b10;
  --surface: #0f1720;
  --ink: #e8f4fc;
  --ink-soft: #8ba3b5;
  --navy: #e8f4fc;
  --brand: #38bdf8;
  --brand-bright: #7dd3fc;
  --brand-dark: #0ea5e9;
  --brand-glow: rgba(56, 189, 248, 0.28);
  --panel-bg: #061018;
  --panel-ink: #e8f4fc;
  --panel-muted: rgba(186, 230, 253, 0.72);
  --border: #1e3344;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --header-bg: rgba(7, 11, 16, 0.92);
  --ok: #5eead4;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #7dd3fc;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--brand); text-underline-offset: 3px; }
a:hover { color: var(--brand-dark); }

img { max-width: 100%; display: block; }

.shell { width: min(1120px, 100% - 2rem); margin-inline: auto; }

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--ink);
}

.brand:hover { color: var(--ink); }

.site-logo {
  width: 2.25rem;
  height: 2.25rem;
  object-fit: contain;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.1rem;
}

.brand-name span { color: var(--brand); }
[data-theme="dark"] .brand-name span { color: var(--brand-bright); }

.theme-toggle,
.menu-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
}

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.menu-btn { display: none; gap: 5px; }
.menu-btn span { display: block; width: 16px; height: 2px; background: var(--ink); }

.guest-body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 55% at 12% 0%, rgba(125, 211, 252, 0.28), transparent 55%),
    var(--bg);
}

.auth-shell {
  min-height: calc(100vh - 5rem);
  display: grid;
  place-items: center;
  padding: 2rem 1rem 3rem;
}

.auth-card,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.auth-card { width: min(32rem, 100%); }
.auth-card.plan-catalog { width: min(72rem, 100%); }
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}
.plan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  text-align: left;
}

.eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
}

.eyebrow.product {
  letter-spacing: -0.02em;
  text-transform: none;
}

h1, h2, h3 { letter-spacing: -0.03em; color: var(--navy); margin: 0 0 0.65rem; }
.muted { color: var(--ink-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 0.7rem 1.15rem;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.btn-main { background: var(--brand); color: #fff; box-shadow: 0 8px 24px var(--brand-glow); }
.btn-main:hover { background: var(--brand-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand-dark); }
.btn-soft { background: rgba(255,255,255,0.08); color: var(--panel-ink); border-color: rgba(255,255,255,0.14); }
.btn-small { padding: 0.4rem 0.75rem; font-size: 0.82rem; border-radius: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 1rem; }

.stack-form { display: grid; gap: 0.85rem; }
.stack-form h2, .stack-form h3 { margin-top: 0.75rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.table form { display: grid; gap: 0.35rem; justify-items: start; }
.line-items .form-grid { grid-template-columns: 2fr 0.7fr 1fr; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; }

label { display: grid; gap: 0.35rem; font-size: 0.875rem; font-weight: 600; }
label.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: max-content;
  max-width: 100%;
  font-weight: 500;
  cursor: pointer;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
select,
textarea {
  width: 100%;
  font: inherit;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  border: 0;
  border-radius: 0;
  background: none;
  accent-color: var(--brand);
  cursor: pointer;
}

.input-with-suffix {
  display: flex;
  align-items: stretch;
  min-width: 0;
}

.input-with-suffix input {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-with-suffix .suffix {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 0 0.8rem;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 10px 10px 0;
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 600;
  white-space: nowrap;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(2, 132, 199, 0.4);
  border-color: var(--brand);
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
  outline: 2px solid rgba(2, 132, 199, 0.4);
  outline-offset: 2px;
}

.app-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  background: #0c4a6e;
}
[data-theme="dark"] .app-body { background: #061018; }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 10;
  align-self: start;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 80% 40% at 0% 0%, rgba(125, 211, 252, 0.2), transparent 55%),
    linear-gradient(180deg, #0c4a6e 0%, #0369a1 100%);
  background-size: 100% 100vh;
  background-size: 100% 100dvh;
  background-repeat: no-repeat;
  color: var(--panel-ink);
  padding: 1.15rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #061018 0%, #0a1f2e 100%);
  background-size: 100% 100vh;
  background-size: 100% 100dvh;
  background-repeat: no-repeat;
}

.sidebar .brand { color: #fff; }
.sidebar .brand-name span { color: var(--brand-bright); }

.side-nav { display: grid; gap: 0.2rem; }
.side-nav a {
  color: var(--panel-muted);
  text-decoration: none;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-weight: 600;
}
.side-nav a:hover,
.side-nav a[aria-current="page"] {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.side-foot { margin-top: auto; }
.who { display: grid; margin-bottom: 0.6rem; }
.who strong { color: #fff; }
.who span { font-size: 0.8rem; color: var(--panel-muted); }

.app-main { min-width: 0; background: var(--bg); }
.app-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-top h1 { margin: 0; font-size: 1.2rem; flex: 1; }
.app-content { padding: 1.25rem 1.4rem 2.5rem; display: grid; gap: 1.1rem; }

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.card-head h2,
.card-head h3 { margin: 0; }

.server-block {
  padding: 1.15rem 0;
  border-top: 1px solid var(--border);
}
.server-block:first-of-type { border-top: 0; padding-top: 0.35rem; }
.server-block .btn-row { margin-top: 0.75rem; }
.server-block + .server-block form[action*="cwp/test"] { margin-top: 0.4rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-card span { color: var(--ink-soft); font-size: 0.82rem; font-weight: 600; }
.stat-card strong { display: block; font-size: 1.7rem; letter-spacing: -0.04em; color: var(--navy); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 0.7rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--ink-soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table form { margin: 0; }
.table tr.is-child td { background: rgba(2, 132, 199, 0.05); }
.table .child-mark { color: var(--ink-soft); margin-right: 0.35rem; }

.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.mini-block { padding: 0.5rem 0; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-ok { background: rgba(15, 118, 110, 0.12); color: var(--ok); }
.badge-warn { background: rgba(180, 83, 9, 0.12); color: var(--warn); }
.badge-bad { background: rgba(180, 35, 24, 0.12); color: var(--bad); }
.badge-info { background: rgba(2, 132, 199, 0.12); color: var(--info); }
.badge-muted { background: var(--bg); color: var(--ink-soft); }

.flash {
  padding: 0.8rem 1rem;
  border-radius: 10px;
  font-weight: 500;
}
.flash-success { background: #d1e7dd; color: #0f5132; border: 1px solid #a3cfbb; }
.flash-error { background: #f8d7da; color: #842029; border: 1px solid #f1aeb5; }
.flash-warn { background: #fff3cd; color: #664d03; border: 1px solid #ffe69c; }
[data-theme="dark"] .flash-success { background: rgba(15,81,50,.35); color: #a3cfbb; }
[data-theme="dark"] .flash-error { background: rgba(132,32,41,.35); color: #f1aeb5; }
[data-theme="dark"] .flash-warn { background: rgba(102,77,3,.35); color: #ffe69c; }

.hero-mini {
  background:
    radial-gradient(ellipse 70% 55% at 12% 15%, rgba(125, 211, 252, 0.28), transparent 55%),
    linear-gradient(165deg, #0c4a6e 0%, #0369a1 55%, #0ea5e9 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.6rem;
}
.hero-mini h2 { color: #fff; }
.hero-mini p { color: var(--panel-muted); margin: 0; }
[data-theme="dark"] .hero-mini {
  background: linear-gradient(165deg, #061018 0%, #0a1f2e 50%, #0c2d42 100%);
}

.totals { text-align: right; }
.field-static { display: flex; align-items: center; gap: 0.5rem; padding-top: 1.6rem; }
.table-actions { white-space: nowrap; font-size: 0.85rem; }
.card-head .invoice-pdf-actions,
.card-head .btn-row { margin-top: 0; }
.invoice-pdf-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.btn-row .invoice-pdf-actions { display: contents; }

.ticket-thread { display: grid; gap: 0.75rem; margin: 1rem 0 1.25rem; }
.ticket-msg {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.ticket-msg.is-staff {
  border-color: rgba(2, 132, 199, 0.35);
  background: rgba(2, 132, 199, 0.06);
}
.ticket-msg-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem 1rem;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
}
.ticket-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ticket-msg.is-internal {
  border-style: dashed;
  background: rgba(180, 83, 9, 0.08);
}
.impersonate-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
  padding: 0.55rem 1rem;
  background: #b45309;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
}
.impersonate-bar form { margin: 0; }
.badge-warn { background: rgba(180, 83, 9, 0.14); color: var(--warn); }

.invoice-print-body {
  min-height: 100vh;
  background: #e8f1f8;
  color: #0c1a28;
}

.invoice-print-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: min(800px, 100% - 2rem);
  margin: 1rem auto 0;
}

.invoice-sheet {
  width: min(800px, 100% - 2rem);
  margin: 1rem auto 2.5rem;
  background: #fff;
  color: #0c1a28;
  border: 1px solid #cfe8f7;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(12, 74, 110, 0.08);
  padding: 2.2rem 2.4rem 1.8rem;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.invoice-sheet-top,
.invoice-sheet-parties {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.6rem;
}

.invoice-sheet-meta { text-align: right; }
.invoice-sheet-meta h1 { margin: 0.15rem 0 0.45rem; }
.invoice-sheet-dates { margin: 0; display: grid; gap: 0.4rem; }
.invoice-sheet-dates div { display: grid; grid-template-columns: 4.5rem 1fr; gap: 0.5rem; }
.invoice-sheet-dates dt { margin: 0; color: #4a6578; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.invoice-sheet-dates dd { margin: 0; }
.invoice-sheet-table thead th {
  background: #0284c7;
  color: #fff;
  border-bottom-color: #0284c7;
}
.invoice-sheet-table th:nth-child(2),
.invoice-sheet-table td:nth-child(2),
.invoice-sheet-table th:nth-child(3),
.invoice-sheet-table td:nth-child(3),
.invoice-sheet-table th:nth-child(4),
.invoice-sheet-table td:nth-child(4) { text-align: right; }
.invoice-sheet-totals { margin-top: 1rem; }
.invoice-sheet-foot { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #cfe8f7; }

@media print {
  .invoice-print-toolbar { display: none; }
  .invoice-print-body { background: #fff; }
  .invoice-sheet {
    width: auto;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }
}

@media (max-width: 900px) {
  .app-body { grid-template-columns: 1fr; background: var(--bg); }
  .sidebar { display: none; }
  body.nav-open .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    height: 100%;
    z-index: 50;
  }
  .menu-btn { display: grid; }
  .split, .form-grid, .line-items .form-grid { grid-template-columns: 1fr; }
}
