:root {
  --bg: #e8e2d6;
  --bg-deep: #d6cfc0;
  --ink: #1a1f1c;
  --muted: #5a635c;
  --panel: rgba(255, 252, 246, 0.92);
  --line: rgba(26, 31, 28, 0.12);
  --accent: #0f6b5c;
  --accent-2: #c45c26;
  --danger: #9b2c2c;
  --ok: #1f6b3a;
  --shadow: 0 18px 50px rgba(26, 31, 28, 0.12);
  --font: "Instrument Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #f4efe4 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #cfe8e1 0%, transparent 45%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
  min-height: 100vh;
}

code { font-family: var(--mono); font-size: 0.9em; }

.view { min-height: 100vh; }
[hidden] { display: none !important; }

/* Login */
.login-view {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  min-height: 100vh;
}
.login-panel {
  padding: clamp(2rem, 5vw, 4.5rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 540px;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.05rem;
  color: var(--accent);
  margin: 0 0 1rem;
}
.login-panel h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
  margin: 0 0 0.75rem;
}
.lede { color: var(--muted); margin: 0 0 2rem; max-width: 36ch; }
.login-visual {
  background:
    linear-gradient(145deg, rgba(15, 107, 92, 0.88), rgba(196, 92, 38, 0.55)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cpath fill='none' stroke='rgba(255,255,255,0.18)' stroke-width='1' d='M0 40h160M0 80h160M0 120h160M40 0v160M80 0v160M120 0v160'/%3E%3C/svg%3E");
  background-size: cover, 48px 48px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 1rem;
}
input, textarea, select {
  font: inherit;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  color: var(--ink);
}
textarea { resize: vertical; font-family: var(--mono); font-size: 0.86rem; line-height: 1.45; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(15, 107, 92, 0.35);
  border-color: var(--accent);
}

.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--accent); color: #f4fff9; }
.btn.secondary { background: var(--ink); color: #f7f3ea; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.sm { padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.btn.danger { background: var(--danger); color: #fff; }

.hint { color: var(--muted); font-size: 0.88rem; }
.error { color: var(--danger); font-weight: 500; }
.ok { color: var(--ok); font-weight: 500; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-lockup { display: flex; align-items: center; gap: 0.75rem; min-width: 180px; }
.pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(15, 107, 92, 0.12);
  color: var(--accent);
}
.pill.bad { background: rgba(155, 44, 44, 0.12); color: var(--danger); }
.tabs { display: flex; gap: 0.35rem; flex: 1; flex-wrap: wrap; }
.tab {
  font: inherit;
  font-weight: 600;
  background: transparent;
  border: none;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}
.tab.active { background: var(--ink); color: #f7f3ea; }

main {
  padding: clamp(1.25rem, 3vw, 2.25rem);
  max-width: 1100px;
  margin: 0 auto;
}
.section-head { margin-bottom: 1.5rem; }
.section-head h2 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}
.section-head p { margin: 0; color: var(--muted); }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat .n {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.stat .l { color: var(--muted); font-size: 0.85rem; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.job-status { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); }

.log-block, .form-grid, .stack, .mailbox-list article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.log-head h3 { margin: 0; font-size: 1rem; }
.log-list {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1rem;
  margin-bottom: 1.25rem;
}
.form-actions { grid-column: 1 / -1; display: flex; gap: 0.6rem; }
.check {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  margin-top: 1.6rem;
}
.check input { width: auto; }

.mailbox-list { display: grid; gap: 0.75rem; padding: 0; background: transparent; border: none; box-shadow: none; }
.mailbox-list article {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}
.mailbox-list h4 { margin: 0 0 0.2rem; }
.mailbox-list p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.mb-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.stack { display: flex; flex-direction: column; }
.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2rem 0;
}

.inbox-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 1.2fr);
  gap: 1rem;
  min-height: 420px;
}
.inbox-list, .inbox-detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: 70vh;
}
.inbox-list { padding: 0.35rem; }
.inbox-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-bottom: 1px solid var(--line);
}
.inbox-item:hover, .inbox-item.active { background: rgba(15, 107, 92, 0.08); }
.inbox-item.unread .subj { font-weight: 700; }
.inbox-item .from { font-size: 0.85rem; color: var(--muted); }
.inbox-item .subj { margin: 0.15rem 0; }
.inbox-item .meta { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }
.inbox-detail { padding: 1.25rem; }
.inbox-detail h3 { margin: 0 0 0.35rem; letter-spacing: -0.02em; }
.inbox-detail .fromline { color: var(--muted); margin-bottom: 1rem; font-size: 0.92rem; }
.inbox-body {
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 1rem 0 1.25rem;
  max-height: 40vh;
  overflow: auto;
}
.forever-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
}
@media (max-width: 860px) {
  .inbox-layout { grid-template-columns: 1fr; }
  .login-view { grid-template-columns: 1fr; }
  .login-visual { min-height: 180px; order: -1; }
  .form-grid, .inline-fields { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
