:root {
  --bg: #ffffff;
  --sidebar: #f7f6f3;
  --panel: #ffffff;
  --panel-2: #f7f6f3;
  --hover: rgba(55, 53, 47, 0.08);
  --hover-strong: rgba(55, 53, 47, 0.12);
  --text: #37352f;
  --muted: #787774;
  --line: rgba(55, 53, 47, 0.09);
  --line-strong: rgba(55, 53, 47, 0.16);
  --accent: #2383e2;
  --accent-hover: #1b7bd6;
  --accent-soft: rgba(35, 131, 226, 0.12);
  --green: #0f7b6c;
  --green-bg: #ddeddb;
  --red: #c4554d;
  --red-bg: #fbe4e4;
  --yellow: #c19138;
  --yellow-bg: #fbf3db;
  --blue-tag: #337ea9;
  --blue-tag-bg: #d3e5ef;
  --shadow: 0 4px 18px rgba(15, 15, 15, 0.08), 0 1px 3px rgba(15, 15, 15, 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  --sidebar-width: 244px;
  --radius: 6px;
  --radius-lg: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

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

button, input, select {
  font-family: inherit;
}

/* ── Auth ── */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: var(--sidebar);
}

.auth-card {
  width: min(380px, 100%);
  padding: 28px 28px 32px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.brand, .workspace {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand { margin-bottom: 24px; }

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.04em;
  color: #fff;
  background: #37352f;
  flex-shrink: 0;
}

.brand-mark.compact-mark {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 12px;
}

.brand h1,
.brand strong,
.workspace strong {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand p,
.brand span,
.workspace span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin: 1px 0 0;
}

.auth-form label,
.config-form label {
  display: grid;
  gap: 6px;
  margin-bottom: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.auth-form { display: grid; gap: 14px; }

input, select {
  width: 100%;
  height: 34px;
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:hover, select:hover {
  background: rgba(55, 53, 47, 0.03);
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  background: var(--bg);
}

button {
  border: 0;
  border-radius: var(--radius);
  height: 34px;
  padding: 0 12px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

button:hover { background: var(--accent-hover); }
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary,
.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-secondary {
  border: 1px solid var(--line-strong);
}

.btn-secondary:hover,
.btn-ghost:hover {
  background: var(--hover);
}

.btn-success { background: var(--green); }
.btn-success:hover { background: #0c6b5e; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b1443d; }

/* ── App shell ── */

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.workspace {
  padding: 6px 8px 10px;
  border-radius: var(--radius);
  margin-bottom: 4px;
}

.workspace:hover { background: var(--hover); }

.workspace-meta {
  min-width: 0;
}

.workspace-meta strong,
.workspace-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  text-align: left;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  opacity: 0.55;
  flex-shrink: 0;
}

.nav-item:hover { background: var(--hover); }
.nav-item.active {
  background: var(--hover-strong);
}
.nav-item.active svg { opacity: 0.8; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 6px 4px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.sidebar-footer .btn-ghost {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  height: 30px;
  color: var(--muted);
}

.sidebar-backdrop { display: none; }

.sidebar-toggle {
  display: none;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.sidebar-toggle:hover { background: var(--hover); }

.main-shell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 8;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
}

.page-header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 12px 48px 8px;
}

.page-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.page-icon {
  font-size: 28px;
  line-height: 1;
}

.page-header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-content {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 8px 48px 64px;
}

/* ── Content ── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 22px;
}

.card {
  padding: 14px 16px;
  background: var(--panel-2);
  border-radius: var(--radius-lg);
}

.card h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.metric {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hint, .muted { color: var(--muted); font-size: 12px; }
.mono { font-family: var(--mono); font-size: 13px; word-break: break-all; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 10px;
  margin-bottom: 22px;
}

.panel {
  margin-bottom: 22px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 4px 0 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.panel-body { padding: 0; }

.details-list {
  display: grid;
  gap: 2px;
  margin: 0;
}

.details-list div {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  padding: 7px 8px;
  border-radius: var(--radius);
}

.details-list div:hover { background: var(--hover); }
.details-list dt { color: var(--muted); font-size: 13px; }
.details-list dd { margin: 0; overflow-wrap: anywhere; }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.tag-copy { background: var(--green-bg); color: var(--green); }
.tag-skip { background: var(--red-bg); color: var(--red); }
.tag-info { background: var(--blue-tag-bg); color: var(--blue-tag); }

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.badge-online { background: var(--green-bg); color: var(--green); }
.badge-offline { background: var(--red-bg); color: var(--red); }
.badge-dry { background: var(--yellow-bg); color: var(--yellow); }
.badge-live { background: var(--green-bg); color: var(--green); }

.alert {
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}

.alert-error {
  background: var(--red-bg);
  color: var(--red);
}

.feed {
  display: grid;
  gap: 6px;
  max-height: 360px;
  overflow: auto;
}

.feed-item {
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  background: var(--panel-2);
}

.feed-item .meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.filters { display: flex; gap: 4px; flex-wrap: wrap; }

.filter-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  height: 26px;
  padding: 0 8px;
  font-weight: 500;
  font-size: 13px;
}

.filter-btn:hover { background: var(--hover); color: var(--text); }

.filter-btn.active {
  background: var(--hover-strong);
  color: var(--text);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

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

th, td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(55, 53, 47, 0.03); }

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  background: var(--panel-2);
}

.reason-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
}

.reason-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--panel-2);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

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

.config-form {
  display: grid;
  gap: 12px;
}

.config-form fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin: 0;
}

.config-form legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
}

.config-form.narrow { max-width: 420px; }

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.checkbox-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.log-view {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--panel-2);
  border: 1px solid var(--line);
  max-height: 420px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.hidden { display: none; }
.toast-success { color: var(--green); }
.toast-error { color: var(--red); }
.toast-info { color: var(--blue-tag); }

.watchlist-intro { margin: 0; }

.watchlist-panel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.watchlist-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

button.preset-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  white-space: normal;
  line-height: 1.45;
  box-shadow: none;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

button.preset-card .preset-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

button.preset-card .preset-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

button.preset-card:hover {
  background: var(--panel-2);
  border-color: rgba(35, 131, 226, 0.35);
  box-shadow: 0 0 0 1px rgba(35, 131, 226, 0.08);
}

button.preset-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px rgba(35, 131, 226, 0.12);
}

button.preset-card.active:hover {
  background: var(--accent-soft);
}

button.preset-card:disabled {
  opacity: 0.6;
  cursor: wait;
}

.watchlist-status {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

.watchlist-restart { margin: 0; }

@media (max-width: 720px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 20;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  .app-body.sidebar-open .sidebar { transform: none; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(15, 15, 15, 0.35);
  }
  .app-body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar-toggle { display: grid; place-items: center; }
  .page-header-inner, .page-content { padding-left: 16px; padding-right: 16px; }
  .page-header h1 { font-size: 24px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .details-list div { grid-template-columns: 1fr; }
}
