/* MaxHub Cloud operator console — light theme, mobile-first.
   No build step: plain CSS, custom properties, flexbox/grid. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e1e6eb;
  --text: #1b2430;
  --text-muted: #667085;
  --accent: #1f6feb;
  --accent-hover: #1a5fce;
  --accent-contrast: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #e8f6ec;
  --warn: #9a6700;
  --warn-bg: #fff6e0;
  --err: #c9302c;
  --err-bg: #fdecea;
  --muted-bg: #eef1f4;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.06), 0 1px 6px rgba(20, 30, 40, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 15px;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
small, .muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
hr { border: none; border-top: 1px solid var(--border); margin: 1.25em 0; }

/* --- shell / layout ----------------------------------------------------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav-links a {
  color: var(--text-muted); padding: .4rem .65rem; border-radius: var(--radius-sm);
  font-weight: 500; font-size: .92rem;
}
.nav-links a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-links a.active { background: var(--muted-bg); color: var(--text); }
.nav-right { display: flex; align-items: center; gap: .5rem; font-size: .88rem; flex-wrap: wrap; }
.nav-right form { margin: 0; }
.lang-switch a { padding: .2rem .4rem; color: var(--text-muted); }
.lang-switch a.active { color: var(--text); font-weight: 700; }

.main { flex: 1; max-width: 1180px; margin: 0 auto; padding: 1rem; width: 100%; }
.main-narrow { max-width: 640px; }
.footer { text-align: center; color: var(--text-muted); font-size: .82rem; padding: 1.5rem 1rem; }

/* --- primitives ----------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.card > h2, .card > h3 { margin-top: 0; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(5, 1fr); } }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; text-align: center; }
.stat .n { font-size: 1.5rem; font-weight: 700; display: block; }
.stat .l { font-size: .78rem; color: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: var(--radius-sm);
  padding: .5rem .85rem; font-size: .9rem; font-weight: 600; cursor: pointer;
  min-height: 40px; line-height: 1.1;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { filter: brightness(0.93); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; min-height: 30px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px;
  padding: .12rem .55rem; font-size: .76rem; font-weight: 700; background: var(--muted-bg); color: var(--text-muted);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-err { background: var(--err-bg); color: var(--err); }
.badge-dot { width: .5em; height: .5em; border-radius: 50%; background: currentColor; display: inline-block; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 650; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; color: var(--text); }
input[type=text], input[type=password], input[type=number], input[type=url],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .92rem; font-family: inherit; background: var(--surface); color: var(--text); min-height: 40px;
}
textarea { min-height: 320px; font-family: var(--font-mono); font-size: .82rem; line-height: 1.4; }
textarea.small { min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-group { margin-bottom: .85rem; }
.form-inline { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }
.checkbox-row { display: flex; align-items: center; gap: .4rem; font-weight: 500; font-size: .88rem; }
.checkbox-row input { width: auto; min-height: auto; }
.hint { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; margin: 0 0 1rem; }
legend { font-weight: 650; padding: 0 .4rem; }

.flash { border-radius: var(--radius); padding: .6rem .85rem; margin-bottom: 1rem; font-size: .9rem; border: 1px solid transparent; white-space: pre-line; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3c8; }
.flash-err { background: var(--err-bg); color: var(--err); border-color: #f3c3c0; }
.flash-pending { background: var(--warn-bg); color: var(--warn); border-color: #f0dfa8; }

.panel-title { display: flex; align-items: center; gap: .5rem; }
.panel-title .badge { margin-left: auto; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; font-size: .88rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.wizard-steps { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1.25rem; }
.wizard-steps span {
  padding: .3rem .65rem; border-radius: 999px; background: var(--muted-bg); color: var(--text-muted); font-size: .82rem; font-weight: 650;
}
.wizard-steps span.current { background: var(--accent); color: #fff; }
.wizard-steps span.done { background: var(--ok-bg); color: var(--ok); }

.qr-box { background: #fff; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius); display: inline-block; }
.qr-box svg { width: 220px; height: 220px; display: block; }
.code-display { font-family: var(--font-mono); font-size: 1.15rem; letter-spacing: .04em; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .8rem; word-break: break-all; }

.diff-line { font-family: var(--font-mono); font-size: .8rem; white-space: pre-wrap; padding: 0 .4rem; border-radius: 3px; }
.diff-add { background: #e6ffed; color: #1a7f37; }
.diff-del { background: #ffebe9; color: #c9302c; }
.diff-same { color: var(--text-muted); }

.sparkline-wrap { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; }
.spark-line { stroke: var(--accent); stroke-width: 2; }
.spark-dot { fill: var(--accent); }
.spark-baseline { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 80vh; padding: 1rem; }
.login-card { max-width: 380px; width: 100%; }

.device-tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .75rem; }
.device-tabs a { padding: .3rem .6rem; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: .82rem; }
.device-tabs a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.row-repeat { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: .5rem; margin-bottom: .5rem; }
.row-repeat .grid { gap: .5rem; }

.days-grid { display: flex; gap: .3rem; flex-wrap: wrap; }
.days-grid label { display: flex; flex-direction: column; align-items: center; font-size: .72rem; font-weight: 500; gap: .15rem; margin: 0; }

.live-pulse { display: inline-block; width: .55em; height: .55em; border-radius: 50%; background: var(--ok); }
.live-pulse.off { background: var(--text-muted); }

@media (max-width: 719px) {
  .main { padding: .65rem; }
  .card { padding: .75rem; }
  h1 { font-size: 1.3rem; }
}
