:root {
  --bg: #0f1419;
  --bg-elev: #171e26;
  --bg-soft: #1c2530;
  --line: #2a3544;
  --text: #e8eef5;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --accent-2: #1f6fb8;
  --ok: #3cbf8a;
  --warn: #e0a23a;
  --danger: #e35d6a;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61,156,240,.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(60,191,138,.08), transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: rgba(23, 30, 38, .92);
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: .85rem;
  align-items: center;
  padding: .35rem .4rem;
  position: relative;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: block;
  object-fit: cover;
  background: var(--bg-soft);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(61,156,240,.25);
}
.brand strong { display: block; font-size: 1.05rem; }
.brand small { color: var(--muted); font-size: .78rem; }
.sidebar-close {
  display: none;
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: .2rem .4rem;
}

.nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.nav a {
  color: var(--muted);
  padding: .7rem .85rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
}
.nav a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav a.active {
  background: rgba(61,156,240,.14);
  color: #d7ebff;
  box-shadow: inset 0 0 0 1px rgba(61,156,240,.28);
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.user-chip {
  font-size: .9rem;
  color: var(--text);
  font-weight: 600;
}
.logout { color: var(--muted); font-size: .85rem; }

.main {
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
  width: 100%;
}
.mobile-top {
  display: block;
  margin-bottom: 1rem;
}
.mobile-logo-bar {
  display: block;
  margin-bottom: .75rem;
}
.mobile-logo {
  display: block;
  width: 33.333%;
  max-width: 33.333%;
  height: auto;
  object-fit: contain;
  object-position: left center;
}
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.topbar h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 650;
  letter-spacing: -.02em;
  flex: 1;
  min-width: 0;
}
.nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}
.sidebar-backdrop {
  display: none;
}

.content { max-width: 1100px; width: 100%; }
.mobile-list { display: none; }

.flash {
  margin-bottom: 1rem;
  padding: .85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.flash-ok { background: rgba(60,191,138,.12); border-color: rgba(60,191,138,.35); }
.flash-error { background: rgba(227,93,106,.12); border-color: rgba(227,93,106,.35); }
.flash-warn { background: rgba(224,162,58,.12); border-color: rgba(224,162,58,.35); }

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem;
  margin-bottom: 1.25rem;
}
.stats .stat {
  width: auto;
  max-width: none;
  flex: none;
  padding: 1rem 1.1rem;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat .label { color: var(--muted); font-size: .8rem; margin-bottom: .35rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.1rem;
}
.panel h2 {
  margin: 0 0 .9rem;
  font-size: 1.05rem;
  font-weight: 600;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: .9rem;
}
.panel-head h2 { margin: 0; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}
th, td {
  text-align: left;
  padding: .7rem .55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 560;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
td.mono, .mono { font-family: var(--mono); font-size: .86rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge-ok { background: rgba(60,191,138,.15); color: #8be0bc; border-color: rgba(60,191,138,.28); }
.badge-warn { background: rgba(224,162,58,.15); color: #f0c57a; border-color: rgba(224,162,58,.28); }
.badge-danger { background: rgba(227,93,106,.15); color: #f0a0a8; border-color: rgba(227,93,106,.28); }
.badge-muted { background: rgba(139,154,171,.12); color: #b7c3d1; border-color: rgba(139,154,171,.22); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .55rem .95rem;
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn-secondary {
  background: var(--bg-soft);
  border-color: var(--line);
  color: var(--text);
}
.btn-danger {
  background: linear-gradient(180deg, #e35d6a, #b83b48);
}
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid > * {
  min-width: 0;
  max-width: 100%;
}
.form-grid .full { grid-column: 1 / -1; }
label {
  display: block;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: .35rem;
  font-weight: 550;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="tel"],
textarea,
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: .65rem .75rem;
  font: inherit;
}
input[type="date"] {
  display: block;
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  min-width: 0;
}
textarea { min-height: 90px; resize: vertical; }
.help { color: var(--muted); font-size: .8rem; margin-top: .35rem; }
.check {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1.55rem;
  color: var(--text);
  font-size: .92rem;
}
.check input { width: auto; }
.form-actions {
  display: flex;
  gap: .6rem;
  margin-top: 1.1rem;
}
.form-actions.form-row {
  gap: 0;
  display: flex;
  width: 100%;
}
.form-row .col-6 {
  width: 50%;
  max-width: 50%;
  flex: 0 0 50%;
  box-sizing: border-box;
  padding-right: .4rem;
}
.form-row .col-6 + .col-6 {
  padding-right: 0;
  padding-left: .4rem;
}
.btn-block {
  width: 100%;
  text-align: center;
  box-sizing: border-box;
}
.domain-detail-head {
  width: 100%;
}
.actions-modal[hidden] { display: none !important; }
.actions-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.actions-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}
.actions-modal-sheet {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: .5rem;
  box-shadow: 0 -16px 40px rgba(0, 0, 0, .4);
}
.actions-modal-title {
  font-weight: 650;
  font-size: .95rem;
  margin-bottom: .2rem;
}
.actions-modal-sheet form { margin: 0; }
.actions-modal-sheet .btn { width: 100%; }
.actions-modal-subtitle {
  color: var(--muted);
  font-size: .85rem;
  margin: -.15rem 0 .35rem;
  word-break: break-word;
}
.renew-years-form {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: 100%;
}
button.mobile-list-link {
  font: inherit;
  text-align: left;
  width: 100%;
  color: inherit;
  background: var(--bg);
}
tr.is-clickable { cursor: pointer; }
tr.is-clickable:hover td { background: rgba(61, 156, 240, .08); }
@media (min-width: 901px) {
  .actions-modal { align-items: center; padding: 1.25rem; }
  .actions-modal-sheet {
    border-radius: 14px;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 16px 40px rgba(0, 0, 0, .4);
  }
}
.mobile-list-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.mobile-list-chevron {
  font-size: 1.55rem;
  color: var(--muted);
  line-height: 1;
  margin-left: auto;
  flex: 0 0 auto;
  padding-left: .5rem;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(23, 30, 38, .95);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.75rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card .logo {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-bottom: 1.4rem;
}
.login-card h1 {
  margin: 0;
  font-size: 1.35rem;
}
.login-card p.sub {
  margin: .2rem 0 0;
  color: var(--muted);
  font-size: .88rem;
}
.login-card .field { margin-bottom: .9rem; }
.login-card .login-remember {
  margin: .15rem 0 .85rem;
  color: var(--muted);
  font-size: .9rem;
}
.login-card .btn { width: 100%; margin-top: .4rem; }
.login-error {
  background: rgba(227,93,106,.12);
  border: 1px solid rgba(227,93,106,.35);
  color: #f0a0a8;
  padding: .7rem .8rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .9rem;
}

.login-card .logo img.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(61,156,240,.28);
}

.empty {
  color: var(--muted);
  padding: 1.2rem 0;
  text-align: center;
}

.codebox {
  font-family: var(--mono);
  font-size: .8rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; }

  .mobile-top {
    display: block;
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(15, 20, 25, .96);
    backdrop-filter: blur(10px);
    margin: 0 -1rem 1rem;
    padding-top: env(safe-area-inset-top, 0px);
    border-bottom: 1px solid var(--line);
  }
  .mobile-logo-bar {
    display: block;
    padding: .75rem 1rem .45rem;
    text-align: center;
    margin-bottom: 0;
  }
  .mobile-logo {
    display: block;
    width: 70%;
    max-width: 70%;
    height: auto;
    max-height: none;
    margin: 0 auto;
    object-fit: contain;
    object-position: center;
  }
  .topbar {
    margin: 0;
    padding: .45rem 1rem .75rem;
    flex-wrap: nowrap;
  }
  .topbar h1 {
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main {
    padding: 0 1rem 2rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .content {
    max-width: 100%;
    width: 100%;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 40;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }
  .sidebar-backdrop[hidden] { display: none !important; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100vh;
    height: 100dvh;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform .22s ease;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: inline-block; }
  .nav { flex-direction: column; flex-wrap: nowrap; }
  .nav a { padding: .85rem .95rem; font-size: 1rem; }

  .stats,
  .stats-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .65rem;
  }
  .panel.col-12,
  .panel-full {
    width: 100%;
    max-width: 100%;
  }
  .stat { padding: .85rem; }
  .stat .value { font-size: 1.35rem; }

  .form-grid { grid-template-columns: 1fr; }
  .panel { padding: 1rem; }
  .panel-head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: .65rem;
  }
  .panel-head h2 { flex: 1 1 auto; min-width: 0; }

  .table-desktop { display: none !important; }
  .mobile-list {
    display: flex;
    flex-direction: column;
    gap: .75rem;
  }
  .mobile-list-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .3rem;
    padding: .85rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
  }
  .mobile-list-item-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
  }
  a.mobile-list-link:hover,
  a.mobile-list-link:focus {
    border-color: var(--accent);
    outline: none;
  }
  .mobile-list-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .65rem;
    margin-bottom: .15rem;
  }
  .mobile-list-top .badge {
    flex: 0 0 auto;
    margin-top: .1rem;
  }
  .mobile-list-body {
    flex: 1 1 auto;
    min-width: 0;
  }
  .mobile-list-title {
    font-size: .95rem;
    font-weight: 650;
    word-break: break-word;
    min-width: 0;
    margin: 0;
  }
  .mobile-list-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem .65rem;
    align-items: center;
    margin: .35rem 0;
    font-size: .82rem;
    color: var(--muted);
  }
  .mobile-list-actions {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    flex: 0 0 auto;
    width: 96px;
  }
  .mobile-list-actions .btn,
  .mobile-list-actions form { width: 100%; }
  .mobile-list-actions .btn {
    padding: .4rem .45rem;
    font-size: .75rem;
    white-space: nowrap;
  }

  .table-wrap,
  .table-scroll-x {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll-x table { min-width: 560px; }
  .table-sticky-head thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #171e26;
    box-shadow: 0 1px 0 var(--line);
  }
  .panel-head-sticky {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 140px);
    z-index: 4;
    background: var(--bg-elev);
    margin: 0 -1rem .65rem;
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--line);
  }

  table { font-size: .85rem; }
  th, td { padding: .55rem .4rem; }
  .codebox { font-size: .72rem; word-break: break-all; }
  .flash { word-break: break-word; }

  .login-page {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
  .login-card { padding: 1.35rem; width: min(420px, 100%); }
}

@media (max-width: 480px) {
  .mobile-logo {
    width: 70%;
    max-width: 70%;
  }
  .mobile-list-actions { width: 88px; }
}

.error-note {
  color: #f0a0a8;
  margin-top: .35rem;
  font-size: .78rem;
  line-height: 1.35;
  word-break: break-word;
}
.domain-last-error {
  margin: 0 0 1rem;
  word-break: break-word;
}
.domain-last-error strong { display: block; margin-bottom: .25rem; }

.renew-overlay[hidden] { display: none !important; }
.renew-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(8, 12, 16, .72);
}
.renew-card {
  width: min(440px, 100%);
  max-height: min(86vh, 640px);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.35rem 1.25rem 1.2rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.renew-card h2 {
  margin: 0;
  font-size: 1.15rem;
}
.renew-mark {
  position: relative;
  width: 64px;
  height: 64px;
  margin: .15rem auto .85rem;
  border-radius: 50%;
  border: 3px solid rgba(61, 156, 240, .22);
  border-top-color: var(--accent);
  color: var(--accent);
  display: grid;
  place-items: center;
  animation: renew-spin .9s linear infinite;
}
.renew-shield {
  width: 28px;
  height: 28px;
  display: block;
  animation: renew-spin .9s linear infinite reverse;
}
.renew-mark.is-still,
.renew-mark.is-still .renew-shield {
  animation: none;
}
.renew-mark.is-still {
  border-color: rgba(61, 156, 240, .45);
}
.renew-card.is-ok .renew-mark,
.renew-card.is-warn .renew-mark,
.renew-card.is-error .renew-mark {
  animation: none;
  border: 0;
  font-size: 1.45rem;
  font-weight: 700;
}
.renew-card.is-ok .renew-shield,
.renew-card.is-warn .renew-shield,
.renew-card.is-error .renew-shield { display: none; }
.renew-card.is-ok .renew-mark { background: rgba(60, 191, 138, .18); color: var(--ok); }
.renew-card.is-ok .renew-mark::before { content: "✓"; }
.renew-card.is-warn .renew-mark { background: rgba(224, 162, 58, .18); color: var(--warn); }
.renew-card.is-warn .renew-mark::before { content: "!"; }
.renew-card.is-error .renew-mark { background: rgba(227, 93, 106, .18); color: var(--danger); }
.renew-card.is-error .renew-mark::before { content: "!"; }
.renew-domain {
  margin: .35rem 0 0;
  color: var(--text);
  word-break: break-word;
}
.renew-domain[hidden] { display: none; }
.renew-elapsed {
  margin: .55rem 0 0;
  color: var(--accent);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.renew-elapsed[hidden] { display: none; }
.renew-message {
  margin: .75rem 0 0;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
}
.renew-card.is-working .renew-message { text-align: center; }
.renew-hint {
  margin: .7rem 0 0;
  color: var(--muted);
  font-size: .8rem;
  text-align: left;
}
.renew-hint[hidden] { display: none; }
.renew-card .btn { margin-top: 1rem; }
.renew-card .btn[hidden] { display: none !important; }
.renew-ask-actions {
  display: flex;
  gap: .6rem;
  margin-top: 1rem;
}
.renew-ask-actions .btn { flex: 1; margin-top: 0; }
th.col-actions, td.col-actions {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}
.mobile-list-action { align-self: flex-start; margin-top: .45rem; }
.mobile-list-item > .mobile-list-link {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  color: inherit;
}
#renew-ask .renew-message { text-align: center; }
@keyframes renew-spin {
  to { transform: rotate(360deg); }
}

body.nav-lock { overflow: hidden; }
