@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
  --ink: #111111;
  --ink-soft: #6b6b6b;
  --border: #e2e2e2;
  --bg: #ffffff;
  --bg-soft: #f5f5f5;
  --bg-softer: #fafafa;
  --accent: #ef3c28;
  --accent-hover: #d6331f;
  --accent-ink: #ffffff;
  --success: #1a7f4b;
  --success-bg: #e6f5ec;
  --danger: #ef3c28;
  --danger-bg: #fdeae7;
  --pending: #8a6d1f;
  --pending-bg: #fbf1d8;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(17, 17, 17, 0.08);
  --font: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg-soft);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 600; margin: 0; }
p { margin: 0; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------------- login screen ---------------- */
#login-screen, #forgot-screen, #reset-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--ink);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
}

.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card .sub { color: var(--ink-soft); font-size: 13px; margin-bottom: 24px; }
.login-card form { text-align: left; }

/* ---------------- app shell ---------------- */
#app-screen {
  display: none;
  min-height: 100vh;
}
#app-screen.visible { display: flex; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  padding: 6px 10px 22px;
}
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: inline-block; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cfcfcf;
  font-weight: 500;
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
}

.automation-status { display: flex; align-items: center; gap: 6px; color: #cfcfcf; margin-bottom: 10px; }
.dot-status { width: 8px; height: 8px; border-radius: 50%; background: #7a7a7a; flex-shrink: 0; }
.dot-status.ok { background: #35c07a; }
.dot-status.warn { background: var(--accent); }

.who { color: #9c9c9c; font-weight: 600; margin-bottom: 6px; }

/* ---------------- main content ---------------- */
.main { flex: 1; padding: 32px 40px; max-width: 1100px; }

.panel { display: none; animation: fade 0.15s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h2 { font-size: 20px; }
.page-header p { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none;
  border: none;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-soft);
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: var(--danger-bg); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-bg); }

/* ---------------- metric cards ---------------- */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.metric-card.warn { border-color: var(--accent); }
.metric-card .label { font-size: 12px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.metric-card .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.metric-card.warn .value { color: var(--accent); }

/* ---------------- forms ---------------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field input, .field select, .field textarea,
input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], input:not([type]),
select, textarea {
  width: 100%;
  color: var(--ink);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

.form-error {
  display: none;
  color: var(--danger);
  background: var(--danger-bg);
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.form-error.visible { display: block; }

.hint { color: var(--ink-soft); font-size: 12px; margin-top: 6px; }

/* ---------------- tables ---------------- */
table { width: 100%; border-collapse: collapse; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--ink-soft); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--bg-softer); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-softer); }
.mono, td.mono { font-family: var(--mono); font-size: 12.5px; }
.empty-row td { text-align: center; color: var(--ink-soft); padding: 28px 16px; }

/* ---------------- badges ---------------- */
.badge { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 3px 9px; border-radius: 999px; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-pending { background: var(--pending-bg); color: var(--pending); }
.badge-muted { background: var(--bg-soft); color: var(--ink-soft); }

/* ---------------- toolbar / search ---------------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.search-input { max-width: 280px; }

/* ---------------- recipient chips ---------------- */
.chip-suggestions { position: relative; }
.chip-input {
  min-height: 42px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  background: var(--bg);
}
.chip-input input { border: none; outline: none; flex: 1; min-width: 140px; padding: 4px; background: transparent; }

.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-soft); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12.5px; font-weight: 500; }
.chip button { border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px; }
.chip button:hover { color: var(--danger); }

.chip-suggestion-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 10;
  max-height: 220px;
  overflow-y: auto;
}
.chip-suggestion-item { padding: 9px 12px; font-size: 13px; cursor: pointer; }
.chip-suggestion-item:hover { background: var(--bg-softer); }

/* ---------------- template grid ---------------- */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.template-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; background: var(--bg); min-width: 0; overflow-wrap: break-word; word-break: break-word; }
.template-card:hover { border-color: var(--ink); }
.template-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.t-name { font-weight: 600; font-size: 13.5px; overflow-wrap: break-word; word-break: break-word; }
.t-meta { color: var(--ink-soft); font-size: 11.5px; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.t-preview { font-size: 12px; color: var(--ink-soft); margin-top: 8px; line-height: 1.4; overflow-wrap: break-word; word-break: break-word; white-space: normal; }
.t-preview-missing { font-style: italic; }

.param-list { display: flex; flex-direction: column; gap: 10px; }
.bubble { background: var(--bg-softer); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; white-space: pre-wrap; }

/* ---------------- when / recurring ---------------- */
.when-options { display: flex; gap: 8px; }
.when-option { flex: 1; text-align: center; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-soft); }
.when-option.selected { border-color: var(--accent); color: var(--accent); background: var(--danger-bg); }

.day-picker { display: flex; gap: 6px; }
.day-pill { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink-soft); }
.day-pill.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------- confirm box ---------------- */
.confirm-box { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: var(--bg-softer); }
.confirm-box p { font-size: 13px; margin-bottom: 6px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

/* ---------------- modal ---------------- */
.overlay { display: none; position: fixed; inset: 0; background: rgba(17, 17, 17, 0.45); align-items: flex-start; justify-content: center; z-index: 50; overflow-y: auto; padding: 40px 20px; }
.overlay.visible { display: flex; }
.modal { width: 100%; max-width: 420px; background: var(--bg); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.modal h3 { font-size: 16px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------------- toasts ---------------- */
#toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; font-size: 13px; font-weight: 500; padding: 11px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); opacity: 0; transform: translateY(6px); transition: opacity 0.18s ease, transform 0.18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* ---------------- responsive ---------------- */
@media (max-width: 860px) {
  .sidebar { width: 72px; padding: 16px 8px; }
  .brand span:not(.dot), .nav-item, .who, .automation-status span:not(.dot-status) { display: none; }
  .main { padding: 20px; }
  .metrics { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; }
}
