:root {
  --ink: #152238;
  --ink-soft: #2f3f63;
  --paper: #f8f5ee;
  --cream: #fff8e8;
  --accent: #db6a3b;
  --accent-soft: #efb083;
  --teal: #1f8a8a;
  --success: #2f9e44;
  --warning: #b36b00;
  --danger: #c92a2a;
  --line: #ddd5c5;
  --card-shadow: 0 16px 42px rgba(21, 34, 56, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, #ffe7cf 0%, #f8f5ee 40%),
    radial-gradient(circle at 100% 100%, #e7f4f4 0%, rgba(255, 255, 255, 0) 45%),
    var(--paper);
  min-height: 100vh;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(185deg, #102038 0%, #152d4c 65%, #173a59 100%);
  color: #f5f2e8;
  padding: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-weight: 700;
  line-height: 1.2;
  font-size: 1.25rem;
  letter-spacing: 0.3px;
}

.brand small {
  display: block;
  color: #f4c9a0;
  margin-top: 8px;
  font-weight: 500;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 28px 0;
  display: grid;
  gap: 8px;
}

.nav-list a {
  display: block;
  text-decoration: none;
  color: #f0e9d8;
  padding: 11px 13px;
  border-radius: 10px;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.nav-list a:hover,
.nav-list a.active {
  background: rgba(255, 248, 232, 0.12);
  transform: translateX(4px);
}

.nav-list a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.sidebar-toggle:focus-visible {
  outline: 3px solid rgba(239, 176, 131, 0.95);
  outline-offset: 3px;
}

.sidebar-toggle {
  display: none;
  width: 100%;
  margin: 18px 0 10px;
}

.sidebar .cta {
  margin-top: auto;
  background: rgba(255, 248, 232, 0.14);
  border: 1px solid rgba(255, 248, 232, 0.2);
  border-radius: 14px;
  padding: 14px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.main {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}

.page-title {
  margin: 0;
  font-size: 1.85rem;
}

.page-subtitle {
  color: var(--ink-soft);
  margin-top: 6px;
}

.badge {
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.85rem;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  padding: 16px;
  animation: rise 0.4s ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.metric-label {
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.metric-value {
  margin-top: 8px;
  font-size: 2rem;
  font-weight: 700;
}

form {
  display: grid;
  gap: 11px;
}

label {
  display: grid;
  gap: 5px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfbda1;
  border-radius: 10px;
  padding: 10px 11px;
  background: #fffdf8;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

button:disabled,
input[type="submit"]:disabled {
  cursor: wait;
  opacity: 0.72;
}

button.is-busy,
input[type="submit"].is-busy {
  position: relative;
}

button.is-busy::after {
  content: "";
  display: inline-block;
  width: 0.78rem;
  height: 0.78rem;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: -0.12rem;
}

button.primary {
  background: linear-gradient(90deg, var(--accent), #e98f58);
  color: #1a130d;
}

button.secondary {
  background: #fff;
  border: 1px solid var(--line);
}

button.small {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid #ece3d4;
  vertical-align: top;
}

.table th {
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

.tag.hot {
  background: #ffe3e3;
  color: #b02525;
}

.tag.warm {
  background: #fff0d2;
  color: #94600d;
}

.tag.cold {
  background: #e8edf9;
  color: #2b4c82;
}

.tag.open,
.tag.active,
.tag.scheduled,
.tag.replied,
.tag.draft {
  background: #e8f7f7;
  color: #176b6b;
}

.flex {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.alert {
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.alert.error {
  background: #fff1f1;
  color: var(--danger);
  border: 1px solid #ffd4d4;
}

.alert.success {
  background: #ecfff1;
  color: #246f36;
  border: 1px solid #c8f1d4;
}

.confirm-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(92vw, 420px);
}

.confirm-dialog::backdrop {
  background: rgba(16, 32, 56, 0.48);
}

.confirm-dialog__panel {
  margin: 0;
  background: #fffefa;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  padding: 20px;
}

.confirm-dialog__title {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.confirm-dialog__message {
  margin: 0 0 18px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.confirm-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

pre {
  white-space: pre-wrap;
  background: #102038;
  color: #fef6e9;
  padding: 12px;
  border-radius: 10px;
  max-height: 320px;
  overflow: auto;
}

.letterhead-host {
  background: #f2eee4;
  border: 1px solid #dfd5c1;
  border-radius: 12px;
  padding: 12px;
  min-height: 120px;
}

.letterhead-summary {
  margin-bottom: 10px;
  color: var(--ink-soft);
  font-weight: 600;
}

.letterhead-empty {
  color: var(--ink-soft);
}

.letterhead-paper {
  background: #fffefa;
  border: 1px solid #d7c5a7;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 10px 25px rgba(21, 34, 56, 0.08);
}

.letterhead-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.letterhead-brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1b3559;
}

.letterhead-meta {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.letterhead-rule {
  height: 2px;
  margin: 10px 0 14px;
  background: linear-gradient(90deg, #1b3559, #d48a57);
}

.letterhead-address {
  display: grid;
  gap: 3px;
  color: #24344d;
  font-size: 0.92rem;
}

.letterhead-subject {
  margin: 14px 0 8px;
  color: #12233c;
}

.letterhead-body {
  color: #1b2738;
  line-height: 1.55;
}

.letterhead-body p {
  margin: 0 0 10px;
}

.letterhead-signature {
  margin-top: 18px;
  color: #24344d;
}

.letterhead-signature .name {
  margin-top: 8px;
  font-weight: 700;
}

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

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  .sidebar-toggle {
    display: inline-flex;
    justify-content: center;
    align-items: center;
  }

  .sidebar .nav-list,
  .sidebar .cta {
    display: none;
  }

  .sidebar.is-open .nav-list,
  .sidebar.is-open .cta {
    display: grid;
  }

  .sidebar.is-open .cta {
    display: block;
    margin-top: 14px;
  }

  .grid.cols-2,
  .grid.cols-3 {
    grid-template-columns: 1fr;
  }
}
