/* Stock Checker — Anthropic-inspired theme
   Palette: warm cream + coral, Poppins headings, Lora body. */

:root {
  /* Light theme (Anthropic warm cream) */
  --bg:           #faf9f5;
  --bg-elevated:  #ffffff;
  --bg-warm:      #f5f3ec;
  --border:       #e8e6dc;
  --border-strong:#d6d3c7;
  --text:         #141413;
  --text-muted:   #6b6961;
  --text-subtle:  #b0aea5;
  --accent:       #d97757;
  --accent-hover: #c5613f;
  --accent-soft:  #fbe7d9;
  --blue:         #6a9bcc;
  --green:        #788c5d;
  --danger:       #b94d3d;
  --pill-ok-bg:   #e6efdc;
  --pill-ok-fg:   #3f5a1f;
  --pill-warn-bg: #fbe7d9;
  --pill-warn-bd: #f3c8a8;
  --pill-warn-fg: #7c3f1f;
  --pill-err-bg:  #f5dad6;
  --pill-err-fg:  #7a2818;
  --code-bg:      #f5f3ec;
  --focus-ring:   rgba(217,119,87,0.20);
  --shadow-sm:    0 1px 2px rgba(20,20,19,0.04);
  --shadow-md:    0 4px 14px rgba(20,20,19,0.06);
  color-scheme: light;
}

:root[data-theme="dark"] {
  /* Dark theme (warm dark, not cold blue-black) */
  --bg:           #1d1b18;
  --bg-elevated:  #28251f;
  --bg-warm:      #322f29;
  --border:       #3d3a33;
  --border-strong:#4d4940;
  --text:         #f5f3ec;
  --text-muted:   #a8a59a;
  --text-subtle:  #6b6961;
  --accent:       #e08665;
  --accent-hover: #ec9272;
  --accent-soft:  #3a2820;
  --blue:         #7eaad8;
  --green:        #8ba070;
  --danger:       #d4644f;
  --pill-ok-bg:   #2a3520;
  --pill-ok-fg:   #aabd8a;
  --pill-warn-bg: #3a2820;
  --pill-warn-bd: #5c3e2a;
  --pill-warn-fg: #e0a07f;
  --pill-err-bg:  #3a2018;
  --pill-err-fg:  #e88a78;
  --code-bg:      #322f29;
  --focus-ring:   rgba(224,134,101,0.25);
  --shadow-sm:    0 1px 2px rgba(0,0,0,0.30);
  --shadow-md:    0 4px 14px rgba(0,0,0,0.40);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100%;
}

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

h1, h2, h3, h4 {
  font-family: 'Poppins', Arial, sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* ----- Header ----- */
header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  display: flex; align-items: center; justify-content: space-between;
}
header h1 { margin: 0; font-size: 20px; font-weight: 700; }
header h1 .accent { color: var(--accent); }
header nav a {
  margin-left: 22px;
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 14px; font-weight: 500;
  color: var(--text-muted);
}
header nav a:hover { color: var(--text); text-decoration: none; }

main { max-width: 1400px; margin: 32px auto; padding: 0 28px; }
@media (min-width: 1500px) { main { max-width: 92%; } }

/* ----- Cards ----- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 14px; font-size: 17px; font-weight: 600; }

/* ----- Buttons ----- */
button, .btn {
  background: var(--accent);
  color: var(--bg-elevated);
  border: 0;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 13px; font-weight: 500;
  transition: background 0.15s ease, transform 0.05s ease;
  -webkit-tap-highlight-color: transparent;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button:active, .btn:active { transform: translateY(1px); }
button.secondary, .btn.secondary {
  background: var(--bg-warm);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
button.secondary:hover { background: var(--border); border-color: var(--text-subtle); }
button.danger { background: var(--danger); color: white; }
button.danger:hover { background: #9d3d2f; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ----- Forms ----- */
label {
  display: block;
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 12px; font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
input[type="text"], input[type="url"], input[type="number"],
input[type="date"], input[type="time"], input[type="password"],
select, textarea {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Lora', Georgia, serif;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.field { margin-bottom: 14px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 180px; }

/* ----- Tables ----- */
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th {
  font-family: 'Poppins', Arial, sans-serif;
  font-weight: 500; font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.muted { color: var(--text-muted); }

/* ----- Pills ----- */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 11px; font-weight: 500;
}
.pill.ok       { background: var(--pill-ok-bg);   color: var(--pill-ok-fg); }
.pill.changed  { background: var(--pill-warn-bg); color: var(--pill-warn-fg); }
.pill.error    { background: var(--pill-err-bg);  color: var(--pill-err-fg); }
.pill.disabled { background: var(--bg-warm);      color: var(--text-muted); }

/* ----- Banners ----- */
.warning {
  padding: 12px 16px;
  background: var(--pill-warn-bg);
  border: 1px solid var(--pill-warn-bd);
  border-radius: 10px;
  color: var(--pill-warn-fg);
  margin-bottom: 16px;
}
.success {
  padding: 12px 16px;
  background: var(--pill-ok-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--pill-ok-fg);
  margin-bottom: 16px;
}

.flex { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* ----- Element picker ----- */
.picker-wrap {
  position: relative; display: inline-block; max-width: 100%;
  border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden;
  background: var(--bg-warm);
}
.picker-wrap img { display: block; max-width: 100%; height: auto; }
.picker-wrap canvas {
  position: absolute; top: 0; left: 0; cursor: crosshair;
}
.bbox-info {
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 12px; color: var(--text-muted);
}

.checkbox-row label { display: inline-flex; align-items: center; gap: 6px;
  margin-right: 16px; font-size: 13px; color: var(--text); }
.checkbox-row input { width: auto; }

/* ----- Weekday chips ----- */
.weekday-grid { display: flex; gap: 6px; }
.weekday-grid label {
  flex: 1; text-align: center; padding: 8px 0; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 8px;
  font-family: 'Poppins', Arial, sans-serif;
  font-size: 12px; color: var(--text);
  background: var(--bg-elevated);
  margin-bottom: 0;
  transition: background 0.15s, border-color 0.15s;
}
.weekday-grid input { display: none; }
.weekday-grid label.on {
  background: var(--accent); border-color: var(--accent); color: white;
}

/* ----- Tap-friendly defaults ----- */
button, .btn, input, select, textarea {
  font-size: 14px;
  min-height: 38px;
}

.tablewrap { width: 100%; overflow-x: auto; }

/* =========================================================
   Mobile (≤720px) — stacked card layout for tables
   ========================================================= */
@media (max-width: 720px) {
  body { font-size: 14px; }
  header {
    padding: 12px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  header h1 { font-size: 18px; }
  header nav { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
  header nav a {
    margin: 0; padding: 8px 14px;
    background: var(--bg-warm);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
  }
  main { margin: 16px auto; padding: 0 14px; }
  .card { padding: 16px; margin-bottom: 14px; }
  .card h2 { font-size: 16px; }
  .row { flex-direction: column; gap: 8px; }
  .row > .field { min-width: 0; }

  /* Force-wrap long strings ONLY on small screens */
  a, code, pre, td, p, h1, h2, h3, .summary, .bbox-info {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* Table → stacked card */
  table.responsive thead { display: none; }
  table.responsive,
  table.responsive tbody,
  table.responsive tr,
  table.responsive td { display: block; width: 100%; }
  table.responsive tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 8px 0;
    background: var(--bg-elevated);
  }
  table.responsive td { border: 0; padding: 6px 12px; text-align: left; }
  table.responsive td::before {
    content: attr(data-label);
    display: block;
    font-family: 'Poppins', Arial, sans-serif;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    margin-bottom: 2px;
  }

  /* Mode/Trigger/Every/Status share one row */
  table.responsive.monitors-table tr { font-size: 0; }
  table.responsive.monitors-table td { font-size: 13px; }
  table.responsive.monitors-table td:nth-child(2),
  table.responsive.monitors-table td:nth-child(3),
  table.responsive.monitors-table td:nth-child(4),
  table.responsive.monitors-table td:nth-child(5) {
    display: inline-block;
    box-sizing: border-box;
    vertical-align: top;
    padding: 6px 8px;
  }
  table.responsive.monitors-table td:nth-child(2) { width: 18%; }
  table.responsive.monitors-table td:nth-child(3) { width: 38%; }
  table.responsive.monitors-table td:nth-child(4) { width: 18%; }
  table.responsive.monitors-table td:nth-child(5) { width: 26%; }

  /* Action buttons: size to content */
  table.responsive td.actions {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding-top: 8px; padding-bottom: 10px;
    justify-content: flex-start;
  }
  table.responsive td.actions::before { display: none; }
  table.responsive td.actions button {
    flex: 0 0 auto;
    min-width: 0;
    padding: 7px 12px;
    font-size: 12px;
  }

  .tablewrap { overflow-x: hidden; }
  table.responsive td a { overflow-wrap: anywhere; word-break: break-all; }

  .picker-wrap { max-width: 100%; }
  .picker-wrap img,
  .picker-wrap canvas { width: 100% !important; height: auto !important; }

  .weekday-grid { flex-wrap: wrap; }
  .weekday-grid label { flex: 1 1 calc(25% - 6px); }
  .flex { flex-wrap: wrap; }
}

@media (max-width: 380px) {
  header nav a { padding: 7px 11px; font-size: 12px; }
  .card { padding: 14px 12px; }
  table.responsive td { padding: 5px 10px; }
}

/* =========================================================
   Desktop (≥721px) — table layout polish
   ========================================================= */
@media (min-width: 721px) {
  table.responsive th, table.responsive td {
    padding: 12px 14px;
    vertical-align: middle;
  }
  table.responsive tbody tr:hover { background: var(--bg-warm); }

  table.responsive td:nth-child(1) {
    max-width: 280px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  table.responsive td:nth-child(3) {
    max-width: 240px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  table.responsive td a {
    display: inline-block; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    vertical-align: middle;
  }

  table.responsive td.actions {
    text-align: right;
    white-space: nowrap;
    padding-left: 28px;
    width: 1%;
  }
  table.responsive td.actions button {
    display: inline-block;
    padding: 5px 11px;
    margin-left: 5px;
    min-height: 28px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
  }
  table.responsive td.actions button:first-child { margin-left: 0; }
  table.responsive td button.danger[onclick*="delEvent"] {
    padding: 2px 8px; min-height: 24px; font-size: 14px; line-height: 1;
  }
  table.responsive td .pill { vertical-align: middle; }
  table.responsive td:nth-child(5),
  table.responsive td:nth-child(6) { white-space: nowrap; width: 1%; }
}

/* =========================================================
   Human-like status indicators
   ========================================================= */
.ab-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
}
.ab-row {
  display: flex; align-items: center; flex-wrap: wrap;
  padding: 4px 0;
  font-size: 13px;
  gap: 4px;
}
.ab-label { line-height: 1.4; flex: 0 0 auto; margin-right: 4px; }

.dot {
  display: inline-block;
  width: 11px; height: 11px;
  border-radius: 50%;
  margin-right: 12px;
  flex: 0 0 auto;
}
.dot.on  { background: var(--green); box-shadow: 0 0 8px rgba(120,140,93,0.45); }
.dot.off { background: var(--danger); box-shadow: 0 0 8px rgba(185,77,61,0.45); }
.dot.on.live { animation: dot-pulse 2.4s ease-in-out infinite; }
@keyframes dot-pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 6px  rgba(120,140,93,0.45); }
  50%      { transform: scale(1.18); box-shadow: 0 0 16px rgba(120,140,93,0.95); }
}

.info-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 0;
  width: 22px; height: 22px;
  min-height: 22px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.info-btn:hover { color: var(--text); border-color: var(--text-subtle); background: var(--bg-warm); }
.ab-detail {
  flex: 0 0 100%;
  padding: 6px 0 2px 23px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* Inline code */
code {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  color: var(--text);
}

/* ----- Theme toggle / logout buttons ----- */
.theme-toggle, .nav-icon-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 0;
  width: 34px; height: 34px;
  min-height: 34px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  margin-left: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.theme-toggle:hover, .nav-icon-btn:hover {
  color: var(--text);
  background: var(--bg-warm);
  border-color: var(--text-subtle);
  text-decoration: none;
}
.nav-icon-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}
