/* ============================================================
   Central Control — clean admin design system
   Neutral surfaces, hairline borders, tinted status badges
   ============================================================ */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e6eaf2;
  --border-strong: #d4dce9;
  --text: #1c2739;
  --text-soft: #4c5c74;
  --text-mute: #8a97ad;

  --green: #059669;
  --green-dark: #047857;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --amber: #d97706;
  --amber-dark: #b45309;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --red: #dc2626;
  --red-dark: #b91c1c;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --gray: #64748b;
  --gray-bg: #f1f5f9;
  --gray-border: #e2e8f0;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px -2px rgba(15, 23, 42, 0.09), 0 2px 6px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px -8px rgba(15, 23, 42, 0.16), 0 4px 12px -4px rgba(15, 23, 42, 0.09);

  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --t: 0.15s ease;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(37, 99, 235, 0.18); }

button { font: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.55);
  outline-offset: 2px;
}

h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

.hidden { display: none !important; }

/* ---------- Card ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
  font-weight: 600;
  font-size: 13.5px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background var(--t), border-color var(--t), color var(--t), transform var(--t), opacity var(--t);
}
.btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #b9c5d8;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex: none; }

.btn-ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn-ok:hover:not(:disabled) { background: var(--green-dark); border-color: var(--green-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-dark); border-color: var(--red-dark); }
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-mute);
}
.btn-ghost:hover:not(:disabled) { background: var(--gray-bg); color: var(--text-soft); }
.btn-sm { padding: 4px 11px; font-size: 12px; border-radius: 7px; gap: 5px; }
.btn-sm svg { width: 11px; height: 11px; }
.btn-block { width: 100%; padding: 12px; font-size: 14.5px; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-soft);
  position: relative;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.icon-btn:hover { background: #f8fafc; border-color: #b9c5d8; }
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .badge-dot {
  position: absolute;
  top: 7px; right: 7px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--surface);
}

/* ---------- Spinner ---------- */

.spin {
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 50%;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--blue);
  animation: rot 0.8s linear infinite;
}

@keyframes rot { to { transform: rotate(360deg); } }

/* ============================================================
   Login page
   ============================================================ */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 40px 36px 30px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: pop 0.3s ease;
}

.login-brand {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
}
.brand-icon svg { width: 28px; height: 28px; }

.login-brand h1 {
  font-size: 21px;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.login-brand p {
  font-size: 13px;
  color: var(--text-mute);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.field > span {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.field-inner {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-mute);
  transition: border-color var(--t), box-shadow var(--t);
}
.field-inner:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
.field-inner svg { width: 16px; height: 16px; flex: none; }

.field-inner input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font: inherit;
  color: var(--text);
}
.field-inner input::placeholder { color: var(--text-mute); }

.field-eye {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  color: var(--text-mute);
  display: grid;
  place-items: center;
  border-radius: 6px;
  transition: color var(--t);
}
.field-eye:hover { color: var(--text-soft); }
.field-eye svg { width: 18px; height: 18px; }

.login-error {
  padding: 10px 13px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--red-dark);
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  animation: shake 0.4s ease;
}

.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-mute);
}

/* ============================================================
   Console — chrome
   ============================================================ */

.app { padding: 0 28px 130px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 0;
  background: rgba(244, 246, 250, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
}
.brand .brand-icon svg { width: 20px; height: 20px; }
.brand h1 {
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.brand .sub {
  font-size: 12px;
  color: var(--text-mute);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  white-space: nowrap;
}
.live-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
}
.live-pill.ok .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.14); }
.live-pill.err .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14); }
.live-pill.sync .dot { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.operator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--blue-dark);
  background: var(--blue-bg);
}
.avatar svg { width: 14px; height: 14px; }
.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
  transition: background var(--t), color var(--t);
}
.text-btn:hover { color: var(--red-dark); background: var(--red-bg); }

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 22px 0 18px;
}

.stat {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t), background var(--t);
}
.stat:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat:active { transform: translateY(0); }
.stat.active {
  border-color: var(--blue);
  background: var(--blue-bg);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.stat-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-label .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.stat-value {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.c-green { color: var(--green); }
.c-amber { color: var(--amber); }
.c-red   { color: var(--red); }
.c-mute  { color: var(--text-mute); }
.c-blue  { color: var(--blue); }
.c-ink   { color: var(--text); }

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search {
  flex: 1;
  min-width: 240px;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-mute);
  transition: border-color var(--t), box-shadow var(--t);
}
.search:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
.search svg { width: 16px; height: 16px; flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font: inherit;
  color: var(--text);
}
.search input::placeholder { color: var(--text-mute); }
.search kbd {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-mute);
  background: var(--gray-bg);
  border: 1px solid var(--gray-border);
  border-radius: 5px;
  padding: 1px 6px;
}

/* ---------- Machine table ---------- */

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-mute);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #eef2f8;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8fafc; }
tbody tr.selected td { background: var(--blue-bg); }
tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--blue); }

.col-check {
  width: 42px;
  text-align: center;
  padding-left: 10px !important;
  padding-right: 10px !important;
}
.col-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--blue);
}

.m-no {
  font-family: var(--mono);
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
}

.activity {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-soft);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.num.kinah { font-weight: 650; color: var(--text-soft); }

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.row-pending {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue-dark);
  white-space: nowrap;
}

.empty-inline {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-mute);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty-inline svg { width: 38px; height: 38px; opacity: 0.55; }
.empty-inline .empty-title { font-weight: 650; color: var(--text-soft); font-size: 15px; }
.empty-inline .empty-hint { font-size: 13px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge.online,
.badge.running {
  color: var(--green-dark);
  background: var(--green-bg);
  border-color: var(--green-border);
}
.badge.standby {
  color: var(--amber-dark);
  background: var(--amber-bg);
  border-color: var(--amber-border);
}
.badge.offline,
.badge.unknown {
  color: var(--gray);
  background: var(--gray-bg);
  border-color: var(--gray-border);
}

/* ---------- Bulk action bar ---------- */

.bulkbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: rise 0.28s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.bulkbar .bulk-count {
  font-size: 13px;
  font-weight: 650;
  color: var(--text-soft);
  padding: 0 6px;
  white-space: nowrap;
}
.bulkbar .btn { padding: 7px 15px; }

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 18px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Operations drawer ---------- */

.logpanel {
  position: fixed;
  top: 80px;
  right: 20px;
  bottom: 20px;
  width: min(390px, calc(100vw - 40px));
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 44px));
  opacity: 0;
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.28s, visibility 0.28s;
}
.logpanel.open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
}

.logpanel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 18px 10px;
}
.logpanel-head h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.logpanel-head .icon-btn { width: 32px; height: 32px; border-radius: var(--r-sm); }
.logpanel-head .icon-btn svg { width: 15px; height: 15px; }

.oplist {
  flex: 1;
  overflow-y: auto;
  padding: 6px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.oplist::-webkit-scrollbar { width: 8px; }
.oplist::-webkit-scrollbar-thumb {
  background: var(--gray-border);
  border-radius: 8px;
  border: 2px solid var(--surface);
}
.oplist::-webkit-scrollbar-track { background: transparent; }

.oplist-empty {
  margin: auto;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.oplist-empty svg { width: 34px; height: 34px; opacity: 0.55; }

.op {
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: #fafbfd;
  border: 1px solid #eef2f8;
  animation: fade 0.22s ease;
}
.op-head {
  display: flex;
  align-items: center;
  gap: 9px;
}
.op-icon {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.op-icon svg { width: 11px; height: 11px; }
.op-icon .spin { width: 10px; height: 10px; border-width: 2px; }

.op-icon.st-in_progress { color: var(--blue); }
.op-icon.st-success { color: var(--green); background: var(--green-bg); }
.op-icon.st-failure { color: var(--red); background: var(--red-bg); }
.op-icon.st-unknown  { color: var(--amber); background: var(--amber-bg); }

.op-machine {
  font-family: var(--mono);
  font-weight: 650;
  font-size: 12.5px;
  color: var(--text);
}
.op-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 1px 7px;
  border-radius: 5px;
}
.op-tag.start { color: var(--green-dark); background: var(--green-bg); }
.op-tag.stop  { color: var(--red-dark); background: var(--red-bg); }
.op-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.op-msg {
  margin-top: 5px;
  padding-left: 29px;
  font-size: 12px;
  color: var(--text-soft);
  word-break: break-word;
}

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.28s cubic-bezier(0.34, 1.3, 0.64, 1);
  transition: opacity 0.22s, transform 0.22s;
}
.toast.out { opacity: 0; transform: translateX(-12px); }

.t-icon {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.t-icon svg { width: 13px; height: 13px; }
.t-icon.t-ok { color: var(--green); background: var(--green-bg); }
.t-icon.t-err { color: var(--red); background: var(--red-bg); }
.t-icon.t-info { color: var(--blue); background: var(--blue-bg); }
.t-icon.t-run { color: var(--green); background: var(--green-bg); }
.t-icon.t-stop { color: var(--red); background: var(--red-bg); }

.t-body { min-width: 0; }
.t-title { font-size: 13px; font-weight: 650; color: var(--text); line-height: 1.35; }
.t-detail { margin-top: 2px; font-size: 12px; color: var(--text-soft); word-break: break-word; }

.t-close {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  margin-left: auto;
  padding: 2px 4px;
  font-size: 15px;
  line-height: 1;
  color: var(--text-mute);
  border-radius: 5px;
  transition: color var(--t), background var(--t);
}
.t-close:hover { color: var(--text); background: var(--gray-bg); }

/* ---------- Animations ---------- */

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .app { padding: 0 16px 140px; }
  .table-card { border-radius: var(--r-md); }
}

@media (max-width: 760px) {
  .topbar { padding: 12px 0; }
  .sub { display: none; }
  .logpanel { top: 68px; right: 12px; width: calc(100vw - 24px); }
  .toasts { left: 12px; bottom: 12px; }
  .bulkbar { width: calc(100vw - 28px); justify-content: center; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
