@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("/fonts/Sora-VariableFont.ttf") format("truetype-variations"), url("/fonts/Sora-VariableFont.ttf") format("truetype");
}

:root {
  --bg: #0b1220;
  --bg-2: #111a2e;
  --card: #ffffff;
  --page-bg: #f4f6fb;
  --primary: #f97316;
  --primary-dark: #c2410c;
  --primary-light: #ffedd5;
  --accent: #fbbf24;
  --text: #1e2433;
  --muted: #6b7280;
  --border: #e5e9f2;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --error: #dc2626;
  --error-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;
  --neutral: #6b7280;
  --neutral-bg: #e5e7eb;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);
  font-family: "Sora", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
  color: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 700;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: 0.2px;
}
.topbar .brand::before {
  content: "";
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M12 2 3 6v6c0 5.2 3.6 9.9 9 11 5.4-1.1 9-5.8 9-11V6l-9-4Zm0 4.2 5.5 2.4v3.6c0 3.7-2.4 6.9-5.5 7.9-3.1-1-5.5-4.2-5.5-7.9V8.6L12 6.2Zm-1 4.6v5l4-2.5-4-2.5Z'/></svg>") center/contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M12 2 3 6v6c0 5.2 3.6 9.9 9 11 5.4-1.1 9-5.8 9-11V6l-9-4Zm0 4.2 5.5 2.4v3.6c0 3.7-2.4 6.9-5.5 7.9-3.1-1-5.5-4.2-5.5-7.9V8.6L12 6.2Zm-1 4.6v5l4-2.5-4-2.5Z'/></svg>") center/contain no-repeat;
}
.topbar nav { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.topbar .who { opacity: 0.85; }
.topbar .link-btn { color: #cbd5e1; }
.topbar .link-btn:hover { color: #fff; }

.container { max-width: 1040px; margin: 0 auto; padding: 28px 24px 60px; }
h1 { font-size: 23px; margin: 6px 0 20px; font-weight: 700; letter-spacing: -0.2px; }
h2 { font-size: 15.5px; margin: 0 0 14px; font-weight: 700; color: #111827; }
.muted { color: var(--muted); }
.muted.small { font-size: 13px; margin-top: 10px; }
.mobile-only { display: none; }
.search-hidden { display: none !important; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease;
}
.card:hover { box-shadow: var(--shadow-md); }

/* ---------- Forms ---------- */
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; align-items: end; }
.inline-form { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.3px; }
input, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=date] {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-light);
}
input[type=date] { color: var(--text); cursor: pointer; }
input[type=date]::-webkit-calendar-picker-indicator {
  filter: invert(46%) sepia(94%) saturate(1749%) hue-rotate(1deg) brightness(101%) contrast(96%);
  cursor: pointer;
  padding: 3px;
  border-radius: 4px;
  transition: background 0.15s ease;
}
input[type=date]::-webkit-calendar-picker-indicator:hover { background: var(--primary-light); }

.search-input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236b7280'><path d='M15.5 14h-.79l-.28-.27a6.5 6.5 0 1 0-.7.7l.27.28v.79l5 4.99L20.49 19l-4.99-5Zm-6 0a4.5 4.5 0 1 1 0-9 4.5 4.5 0 0 1 0 9Z'/></svg>") no-repeat 12px center / 16px 16px;
  padding-left: 38px;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
  background-color: #fff;
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(249, 115, 22, 0.35); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.align-end { align-self: end; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 2px;
  font-size: 13.5px;
  font-weight: 600;
  transition: color 0.15s ease;
}
.link-btn:hover { color: var(--primary-dark); text-decoration: underline; }
.link-btn.danger { color: var(--error); }
.link-btn.danger:hover { color: #991b1b; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn svg { width: 15px; height: 15px; fill: currentColor; }
.icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.icon-btn.copied { background: var(--ok-bg); color: var(--ok); }
.icon-btn.danger:hover { background: var(--error-bg); color: var(--error); }

/* ---------- Expandable code rows ---------- */
.chevron-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.2s ease;
}
.chevron-btn svg { width: 20px; height: 20px; fill: currentColor; }
.chevron-btn:hover { background: var(--primary-light); color: var(--primary); }
.chevron-btn.open { transform: rotate(180deg); color: var(--primary); }
.code-expand-row { display: none; }
.code-expand-row.open { display: table-row; }
.code-expand-row td { border-bottom: 1px solid var(--border); padding: 0; }
.expand-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f9fd;
  padding: 14px 16px;
}
.expand-info { display: flex; align-items: center; justify-content: space-between; gap: 18px; font-size: 13px; }
.expand-icons { display: flex; gap: 4px; justify-content: flex-end; }

.copy-toast {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  animation: copy-toast-fade 1.2s ease;
}
.copy-toast::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #111827;
}
@keyframes copy-toast-fade {
  0% { opacity: 0; transform: translateX(-50%) translateY(4px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

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

/* ---------- Tap-to-copy box (ikonka ýerine, tutuş guty basylyp kopýalanýar) ---------- */
.tap-copy {
  position: relative;
  cursor: pointer;
  background: #f8f9fd;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.tap-copy:hover { border-color: var(--primary); background: var(--primary-light); }
.tap-copy:active { background: var(--primary-light); }
.tap-copy.copied { background: var(--ok-bg); border-color: var(--ok); }
.tap-copy-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}
.tap-copy-value {
  display: block;
  font-size: 11.5px;
  word-break: break-all;
  color: var(--text);
  background: none;
  padding: 0;
}

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 2px solid var(--border);
}
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: #f8f9fd; }
.table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 14px; white-space: nowrap; align-items: center; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .table { min-width: 480px; }

/* ---------- Badges ---------- */
.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }
.over-limit { color: var(--error); font-weight: 700; }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 13.5px;
  border-left: 4px solid transparent;
}
.alert-error { background: var(--error-bg); color: #991b1b; border-left-color: var(--error); }
.alert-ok { background: var(--ok-bg); color: #166534; border-left-color: var(--ok); }
.alert-info { background: var(--info-bg); color: #075985; border-left-color: var(--info); }

code {
  background: #f1f3f9;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 12.5px;
  word-break: break-all;
  color: #334155;
}

/* ---------- Login page ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(249, 115, 22, 0.35), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(251, 191, 36, 0.28), transparent 45%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
}
.login-box {
  background: #fff;
  padding: 40px 36px;
  border-radius: 16px;
  width: 340px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.login-box .brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.35);
}
.login-box .brand-mark svg { width: 24px; height: 24px; fill: #fff; }
.login-box h1 { font-size: 19px; margin: 0 0 4px; text-align: center; }
.login-box .muted { text-align: center; font-size: 13px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-box .btn { margin-top: 4px; }

/* ---------- Link field (label + copy/QR icons + value box) ---------- */
.field { margin-top: 14px; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
.field-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.link-box {
  display: block;
  background: #f8f9fd;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
}

/* ---------- Usage bar (traffic used / limit) ---------- */
.usage-bar { margin-top: 14px; }
.usage-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.3s ease;
}
.usage-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 600;
}

.usage-cell { min-width: 130px; }
.usage-track.mini { height: 5px; }
.usage-mini-text { display: block; margin-top: 5px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }

/* ---------- QR modal ---------- */
.qr-modal-body { display: flex; justify-content: center; padding: 24px; }
.qr-modal-body img { width: 100%; max-width: 260px; height: auto; border-radius: 8px; }

/* ---------- Section header (title + trigger button) ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { margin: 0; }

/* ---------- Modal (native <dialog>) ---------- */
dialog.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: 92%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  background: var(--card);
}
dialog.modal::backdrop { background: rgba(11, 18, 32, 0.55); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: rise 0.25s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 20px; line-height: 1; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--page-bg); color: var(--text); }
.modal-body { padding: 20px 22px 22px; }
.modal-body .grid-form { grid-template-columns: 1fr; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .container { padding: 16px 12px 40px; }
  .topbar { padding: 12px 16px; }
  .topbar .brand { font-size: 15px; }
  .topbar nav { gap: 10px; font-size: 13px; }
  h1 { font-size: 19px; margin: 4px 0 16px; }
  .card { padding: 14px; }
  .table { font-size: 12.5px; }
  .table th, .table td { padding: 8px 6px; }
  .row-actions { flex-wrap: wrap; gap: 10px; }
  .grid-form { grid-template-columns: 1fr; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .section-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .section-head .btn { width: 100%; }
  .field-label-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .field-actions { align-self: flex-end; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn svg { width: 17px; height: 17px; }
  .link-box { font-size: 11.5px; word-break: break-all; }
  code { font-size: 11.5px; }
  dialog.modal { width: 94%; max-width: none; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .usage-labels { font-size: 11.5px; }
  .usage-cell { min-width: 90px; }
  .expand-icons { justify-content: flex-end; }

  /* Kodlar sanawyny (Ady/Device/Ulanyş/Status) skroll-syz kart görnüşine
     öwürýär - hiç bir öwrenilen zat çepe-saga gyşarylmaýar. */
  .mobile-only { display: inline; }
  .codes-table { min-width: 0 !important; }
  .table-scroll:has(.codes-table) { overflow-x: visible; }
  .codes-table thead { display: none; }
  .codes-table, .codes-table tbody { display: block; width: 100%; }
  .codes-table tr.code-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "name    status"
      "device  device"
      "usage   chevron";
    column-gap: 10px;
    row-gap: 6px;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
  }
  .codes-table tr.code-row td { display: block; border: none; padding: 0; white-space: normal; }
  .codes-table td.td-name { grid-area: name; font-weight: 700; }
  .codes-table td.td-status { grid-area: status; justify-self: end; }
  .codes-table td.td-devices { grid-area: device; font-size: 12.5px; color: var(--muted); }
  .codes-table td.td-usage { grid-area: usage; }
  .codes-table td.td-chevron { grid-area: chevron; justify-self: end; padding: 0; }

  /* Deskto p bilen deň - ýapyk (bukulan) dur, oka basylanda açylýar. */
  .codes-table tr.code-row:has(+ .code-expand-row.open) { border-radius: 10px 10px 0 0; margin-bottom: 0; }
  .codes-table tr.code-expand-row { display: none; }
  .codes-table tr.code-expand-row.open { display: block; margin: 0 0 8px; }
  .codes-table tr.code-expand-row.open td { display: block; padding: 0; }
  .codes-table tr.code-expand-row.open .expand-panel {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
  }
}
