/* ==========================================================================
   OSCam Billing Lite — stylesheet
   Hand-written, no framework, no build step. Replaces the Tailwind-less
   hand-rolled CSS of the React build (~420 lines there, similar here) but
   without shipping any JavaScript bundle.
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e2e5ea;
  --text: #1c2128;
  --muted: #6b7480;
  --accent: #2f6feb;
  --accent-dark: #1f57c3;
  --ok: #1a7f4b;
  --ok-bg: #e7f6ee;
  --warn: #9a6700;
  --warn-bg: #fdf4e3;
  --err: #b42318;
  --err-bg: #fdecea;
  --info-bg: #eaf1fd;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

/* ---------------------------------------------------------------- layout -- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: #14181d;
  color: #c9d1d9;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  padding: 16px 18px 14px;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  border-bottom: 1px solid #22272e;
}
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; color: #7d8590; margin-top: 2px; }

.sidebar nav { padding: 10px 8px; flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 13.5px;
}
.sidebar nav a:hover { background: #21262d; text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar nav a .icon { width: 16px; text-align: center; opacity: .85; }

.sidebar .who {
  padding: 12px 16px;
  border-top: 1px solid #22272e;
  font-size: 12px;
  color: #7d8590;
}
.sidebar .who strong { color: #e6edf3; display: block; font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; flex: 1; min-width: 0; }
.topbar .spacer { flex: 1; }

/* The hamburger only exists below 780px (see the mobile block further down);
   on a desktop it stays out of the way entirely. */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.nav-toggle:hover { background: var(--panel-2); }

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, .5);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.content { padding: 20px 22px 60px; }

/* ------------------------------------------------------------------ cards -- */

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 780px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }

  /* The sidebar becomes an off-canvas drawer. It used to be `display: none`,
     which left phones with no navigation at all - the menu simply vanished. */
  .nav-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 250px;
    flex: 0 0 250px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 26px rgba(0, 0, 0, .35);
  }
  .sidebar.open { transform: translateX(0); }
  .nav-backdrop.show { opacity: 1; pointer-events: auto; }

  /* Lock the page behind the drawer so the menu does not scroll away. */
  body.nav-open { overflow: hidden; }

  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar h1 { font-size: 15px; }
  .content { padding: 14px 14px 48px; }

  .card { padding: 13px 14px; }
  .card h2, .card h3 { margin-bottom: 10px; }
  .metric .value { font-size: 21px; }

  .form-row { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 auto; justify-content: center; }
  .btn-row .btn { flex: 1 1 auto; justify-content: center; }

  .filters { gap: 6px; }
  .filters .field { flex: 1 1 140px; }
  .filters input, .filters select { min-width: 0; }

  .pager { flex-wrap: wrap; }
  td.wrap { min-width: 0; }
  .auth-wrap { padding: 16px; }
  .auth-card { max-width: none; }
}

/* Very narrow phones: the topbar has to give the title room to breathe. */
@media (max-width: 420px) {
  .topbar { padding: 9px 11px; }
  .topbar h1 { font-size: 14px; }
  .content { padding: 12px 11px 44px; }
  .sidebar { width: 84%; flex: 0 0 84%; }
  .card { padding: 12px; }
  table { font-size: 13px; }
  th, td { padding: 7px 8px; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
}
.card h2, .card h3 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.metric { display: flex; flex-direction: column; gap: 3px; }
.metric .value { font-size: 25px; font-weight: 650; letter-spacing: -.02em; }
.metric .label { font-size: 12px; color: var(--muted); }
.metric .hint { font-size: 11.5px; color: var(--muted); }
.metric.ok .value { color: var(--ok); }
.metric.warn .value { color: var(--warn); }
.metric.err .value { color: var(--err); }

/* ----------------------------------------------------------------- tables -- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-wrap { overflow-x: auto; }

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  background: var(--panel-2);
  position: sticky;
  top: 0;
}
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }

.empty { padding: 26px; text-align: center; color: var(--muted); font-size: 13px; }

/* ----------------------------------------------------------------- badges -- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  background: #eef0f3;
  color: #47505c;
  white-space: nowrap;
}
.badge.active, .badge.success, .badge.repaid { background: var(--ok-bg); color: var(--ok); }
.badge.blocked, .badge.error { background: var(--err-bg); color: var(--err); }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.online { background: var(--ok-bg); color: var(--ok); }
.badge.offline { background: #eef0f3; color: #6b7480; }
.badge.role-superadmin { background: #f0e9fd; color: #6b3fc4; }
.badge.role-admin { background: var(--info-bg); color: var(--accent-dark); }
.badge.role-user { background: #eef0f3; color: #47505c; }

/* ---------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: var(--err-bg); border-color: #f3c9c4; color: var(--err); }
.btn.danger:hover { background: #fbdcd8; }
.btn.ok { background: var(--ok-bg); border-color: #bfe3ce; color: var(--ok); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }

/* --------------------------------------------------------------- password -- */

/* Masked server password plus its reveal/copy buttons. The real value only
   ever reaches the DOM after an explicit click (see /actions/reveal-password). */
.pwd { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pwd-value {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: .06em;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  white-space: nowrap;
}
.pwd-value[data-loaded="1"] {
  background: var(--info-bg);
  border-color: #b6cdf5;
  letter-spacing: 0;
}

/* ------------------------------------------------------------------ forms -- */

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="email"],
input[type="search"], input[type="time"], select, textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #cddffb; border-color: var(--accent); }
.field { margin-bottom: 11px; }
.form-row { display: grid; gap: 11px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.form-actions { margin-top: 6px; display: flex; gap: 8px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .field { margin-bottom: 0; }
.filters input, .filters select { min-width: 130px; }

.checkbox { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); }
.checkbox input { width: auto; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.checkbox-group > .checkbox { margin: 0; }

/* ------------------------------------------------------------------ flash -- */

.flash {
  padding: 9px 13px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3ce; }
.flash.err { background: var(--err-bg); color: var(--err); border-color: #f3c9c4; }

/* ------------------------------------------------------------------- feed -- */

.feed { max-height: 340px; overflow-y: auto; }
.feed-item {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  gap: 9px;
  align-items: baseline;
}
.feed-item:last-child { border-bottom: 0; }
.feed-item .when { color: var(--muted); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed-item .what { flex: 1; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #c2c8d0; display: inline-block;
}
.live-dot.on { background: #2ecc71; box-shadow: 0 0 0 3px rgba(46, 204, 113, .18); }
.live-dot.err { background: var(--err); }

/* ------------------------------------------------------------------- misc -- */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.sep { height: 1px; background: var(--border); margin: 14px 0; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }
.pager .spacer { flex: 1; }

details summary { cursor: pointer; font-size: 13px; color: var(--accent); }
details[open] summary { margin-bottom: 10px; }
details.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 15px;
  margin-bottom: 14px;
}

.bar { height: 7px; background: #eef0f3; border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.ok > span { background: var(--ok); }
.bar.warn > span { background: #e0a800; }
.bar.err > span { background: var(--err); }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 390px; }
.auth-card .brand { text-align: center; margin-bottom: 18px; }
.auth-card .brand h1 { margin: 0; font-size: 21px; }
.auth-card .brand p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.auth-links { margin-top: 14px; text-align: center; font-size: 13px; color: var(--muted); }

.code-box {
  font-family: var(--mono);
  font-size: 20px;
  letter-spacing: .12em;
  padding: 12px;
  text-align: center;
  background: var(--info-bg);
  border: 1px dashed #b6cdf5;
  border-radius: var(--radius);
  margin: 10px 0;
}

/* ------------------------------------------------------------------ services --
   The "Службы" page: service state, a live log tail and a restart button.
   The log pane is deliberately dark. It is raw daemon output, not panel
   chrome, and the contrast makes it obvious where the log starts and ends. */

.svc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.svc-head h3 { margin: 0; }

.log-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 12px 0 10px;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
/* `display: flex` above would otherwise beat the `hidden` attribute, and the
   no-JavaScript fallback would show controls that do nothing. */
.toolbar-group[hidden] { display: none; }
.log-toolbar select {
  padding: 3px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
.log-toolbar label { display: inline-flex; align-items: center; gap: 5px; }

.log-box {
  margin: 0;
  padding: 10px 12px;
  background: #10151b;
  color: #d7e1ec;
  border: 1px solid #1f2933;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  max-height: 440px;
  tab-size: 4;
}
.log-box.empty { color: #f0a9a2; }

.err-text { color: var(--err); }

@media (max-width: 780px) {
  .log-box { font-size: 11px; max-height: 320px; }
  .log-toolbar { gap: 8px; }
  .log-toolbar .toolbar-group { flex: 1 1 auto; }
  .log-toolbar .toolbar-group .btn { flex: 1 1 auto; justify-content: center; }
}

/* ---- config editor ---- */

.notice-warn {
  border-left: 3px solid var(--warn);
  background: var(--warn-bg);
  color: #5c4a00;
}

.config-editor {
  display: block;
  width: 100%;
  min-height: 380px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: #fbfcfd;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  overflow: auto;
  resize: vertical;
  tab-size: 4;
}

.config-editor:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

/* Warnings about the file's current content. Deliberately a list: each one
   names a line or a section, and running them together into a paragraph makes
   them much harder to act on. */
.warn-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.warn-list li {
  margin-bottom: 4px;
}

.warn-list li:last-child {
  margin-bottom: 0;
}

@media (max-width: 780px) {
  .config-editor { font-size: 11.5px; min-height: 300px; }
}
