:root {
  --bg: #0c131c;
  --bg-2: #0f1720;
  --panel: #161f2b;
  --panel-2: #1d2836;
  --panel-3: #243244;
  --border: #263449;
  --border-2: #314156;
  --text: #e8eef6;
  --muted: #93a4b8;
  --muted-2: #6d7f94;
  --accent: #4c84ff;
  --accent-2: #3a6fe0;
  --accent-soft: rgba(76, 132, 255, 0.14);
  --green: #33b85b;
  --green-text: #7ee2a8;
  --green-bg: rgba(46, 160, 67, 0.16);
  --red: #e5484d;
  --red-text: #ff9ea0;
  --red-bg: rgba(229, 72, 77, 0.16);
  --amber: #e0a83a;
  --amber-text: #f2cd7f;
  --amber-bg: rgba(224, 168, 58, 0.16);
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --ring: 0 0 0 3px var(--accent-soft);
  --header-h: 60px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(76, 132, 255, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Icons ------------------------------------------------------------------- */
.icon {
  width: 18px; height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 22px; height: 22px; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Topbar ------------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: var(--header-h);
  padding: 0 20px;
  background: rgba(16, 23, 32, 0.85);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15.5px; letter-spacing: .2px;
  white-space: nowrap;
}
.brand .logo {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: #fff; overflow: hidden;
  box-shadow: 0 3px 10px rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.05);
}
.brand .logo img { width: 26px; height: 26px; display: block; }

.nav { display: flex; align-items: center; gap: 4px; }
.nav a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 9px;
  color: var(--muted); font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(76,132,255,.25); }
.nav .sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.nav .who { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 500; padding-left: 2px; }

.menu-toggle {
  display: none;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); width: 40px; height: 40px; border-radius: 9px;
  cursor: pointer; align-items: center; justify-content: center;
}
.menu-toggle:hover { background: var(--panel-3); }

/* Layout ------------------------------------------------------------------ */
.container { max-width: 1140px; margin: 0 auto; padding: 26px 20px 72px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 0; }
.subtitle { color: var(--muted); margin: 0; }
.subtitle a { color: var(--muted); }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

/* Stat cards -------------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.card {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.card .card-top { display: flex; align-items: center; justify-content: space-between; }
.card .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.card .chip { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--panel-3); color: var(--muted); }
.card .v { font-size: 30px; font-weight: 800; margin-top: 8px; letter-spacing: -.5px; }
.card.valid .chip { color: var(--green-text); background: var(--green-bg); }
.card.valid .v { color: var(--green-text); }
.card.expired .chip { color: var(--red-text); background: var(--red-bg); }
.card.expired .v { color: var(--red-text); }
.card.invalid .chip { color: var(--amber-text); background: var(--amber-bg); }
.card.invalid .v { color: var(--amber-text); }
.card.soon .chip { color: var(--amber-text); background: var(--amber-bg); }
.card.soon .v { color: var(--amber-text); }

/* Panels ------------------------------------------------------------------ */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.panel-body { padding: 18px 16px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Form controls ----------------------------------------------------------- */
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, select:hover, textarea:hover { border-color: #3a4d66; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
textarea { min-height: 96px; resize: vertical; width: 100%; }

/* Stacked form fields (add/edit, login, import) fill their column… */
.field input, .field select, .field textarea { width: 100%; }
.field .input-icon { display: block; }
.field .input-icon input { width: 100%; }
/* …but toolbar controls (dashboard search) keep natural width so they sit in one row */
.toolbar select { width: auto; min-width: 150px; }
select { appearance: none; background-image:
  url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2393a4b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
label { display: block; color: var(--muted); margin: 0 0 7px; font-size: 13px; font-weight: 500; }
.field { margin-bottom: 18px; }
.mono { font-family: "Cascadia Code", "JetBrains Mono", "Consolas", ui-monospace, monospace; }
.input-icon { position: relative; display: inline-block; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; z-index: 1; }
.input-icon input { padding-left: 38px; }
.search { width: 280px; max-width: 100%; }
.grow { flex: 1 1 auto; }
/* lookup: let the icon-wrapped input grow and push the button to the right */
.input-icon.grow { display: flex; }
.input-icon.grow input { width: 100%; }

/* Buttons ----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: 10px 15px; cursor: pointer; font: inherit; font-weight: 500;
  text-decoration: none; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .05s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--panel-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--ring); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; box-shadow: 0 4px 14px rgba(76,132,255,.35); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: transparent; border-color: rgba(229,72,77,.5); color: var(--red-text); }
.btn.danger:hover { background: var(--red-bg); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.block { width: 100%; }
.btn .icon { width: 16px; height: 16px; }

/* Table ------------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); position: sticky; top: 0; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
td.hwid { max-width: 380px; }
td.hwid .val { word-break: break-all; font-size: 12.5px; color: #cdd9e7; }
td .name { font-weight: 600; }
td .note { color: var(--muted); font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.valid { color: var(--green-text); background: var(--green-bg); }
.badge.expired { color: var(--red-text); background: var(--red-bg); }
.badge.invalid_expiry, .badge.not_found { color: var(--amber-text); background: var(--amber-bg); }

/* Pagination -------------------------------------------------------------- */
.pagination { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 14px 16px; flex-wrap: wrap; border-top: 1px solid var(--border); }
.pagination .count { margin-right: auto; color: var(--muted); font-size: 13px; }
.pagination a, .pagination span.pg { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border-2); color: var(--muted); }
.pagination a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.pagination .current { background: var(--accent-soft); border-color: rgba(76,132,255,.35); color: var(--text); font-weight: 600; }
.pagination .disabled { opacity: .4; pointer-events: none; }

/* Flash / alerts ---------------------------------------------------------- */
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 15px; border-radius: var(--radius-sm); margin-bottom: 18px; border: 1px solid; }
.flash.success { color: var(--green-text); background: var(--green-bg); border-color: rgba(46,160,67,.4); }
.flash.error { color: var(--red-text); background: var(--red-bg); border-color: rgba(229,72,77,.4); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .icon { width: 34px; height: 34px; color: var(--muted-2); margin-bottom: 10px; }

/* Login ------------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); }
.login-card .logo-lg { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 16px; background: #fff; overflow: hidden; box-shadow: 0 10px 26px rgba(0,0,0,.4), inset 0 0 0 1px rgba(0,0,0,.05); }
.login-card .logo-lg img { width: 50px; height: 50px; display: block; }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; margin-bottom: 22px; }
.login-card .btn.primary { width: 100%; margin-top: 4px; padding: 12px; }

/* Result box (lookup) ----------------------------------------------------- */
.result-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 10px 16px; align-items: start; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 7px; }
.radio-row { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 500; margin-bottom: 10px; }
.radio-row input { width: auto; }

/* Responsive -------------------------------------------------------------- */
@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .menu-toggle { display: inline-flex; }
  .nav {
    position: fixed; inset: var(--header-h) 0 auto 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    padding: 10px; box-shadow: var(--shadow);
    transform: translateY(-8px); opacity: 0; visibility: hidden;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
    z-index: 25;
  }
  .nav.open { transform: translateY(0); opacity: 1; visibility: visible; }
  .nav a { padding: 12px 14px; }
  .nav .sep { display: none; }
  .nav .who { padding: 10px 14px; border-top: 1px solid var(--border); margin-top: 4px; }
  .nav .logout-form { padding: 0 6px 4px; }
  .nav .logout-form .btn { width: 100%; }

  .container { padding: 20px 15px 64px; }
  h1 { font-size: 20px; }

  /* Table -> stacked cards */
  table, thead, tbody, th, td, tr { display: block; }
  table { min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 12px; padding: 6px 4px;
  }
  tbody tr:hover { background: var(--panel-2); }
  tbody tr:last-child td { border-bottom: 1px solid var(--border); }
  td { border: none !important; padding: 8px 14px; display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; }
  td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 11.5px; text-transform: uppercase;
    letter-spacing: .04em; font-weight: 600;
  }
  td.hwid { max-width: none; }
  td.hwid .val { font-size: 12px; }
  .row-actions { justify-content: flex-start; }
  .pagination { justify-content: center; }
  .pagination .count { width: 100%; text-align: center; margin: 0 0 6px; }
}

@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card .v { font-size: 24px; }
  .brand { font-size: 14px; }
  td { grid-template-columns: 84px 1fr; }
}

/* Expiry quick presets (add/edit form) -------------------------------------- */
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.presets .plabel { color: var(--muted); font-size: 12.5px; align-self: center; margin-right: 2px; }
.preset-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-2); background: var(--panel-2); color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .05s ease;
}
.preset-btn:hover { background: var(--accent-soft); border-color: rgba(76,132,255,.45); color: var(--text); }
.preset-btn:active { transform: translateY(1px); }

/* Confirmation modal -------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; padding: 20px;
  background: rgba(6, 10, 16, 0.62); backdrop-filter: blur(3px);
  display: none; place-items: center;
}
.modal-overlay.open { display: grid; }
.modal {
  width: 100%; max-width: 460px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  animation: modal-in .16s ease;
}
@keyframes modal-in { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: 13px; padding: 20px 20px 0; }
.modal-head .warn { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: var(--red-bg); color: var(--red-text); flex: 0 0 auto; }
.modal-head .warn .icon { width: 22px; height: 22px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 12px 20px 4px; color: var(--muted); }
.modal-body .hwid-chip { display: block; margin-top: 12px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; font-size: 12.5px; word-break: break-all; color: #cdd9e7; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 20px 20px; }

@media (max-width: 460px) { .modal-foot { flex-direction: column-reverse; } .modal-foot .btn { width: 100%; } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
