:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-2: #f0f4f7;
  --ink: #17202a;
  --muted: #68737d;
  --line: #d9e0e4;
  --brand: #176c7a;
  --brand-2: #0f5965;
  --accent: #b34e32;
  --ok: #2e7d50;
  --warn: #a15c00;
  --danger: #b3261e;
  --shadow: 0 12px 30px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.1;
}

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #18252b;
  color: #eef5f6;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  font-weight: 800;
  font-size: 20px;
  padding: 8px 6px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button,
.logout {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  padding: 10px 12px;
  text-align: left;
}

.nav button.active,
.nav button:hover,
.logout:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.user-pill {
  color: #c8d7db;
  font-size: 13px;
  padding: 0 6px;
  overflow-wrap: anywhere;
}

.main {
  min-width: 0;
  padding: 22px;
  display: grid;
  gap: 18px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

.textarea {
  min-height: 130px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 108, 122, 0.12);
}

.btn {
  min-height: 38px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 9px 14px;
  font-weight: 700;
}

.btn:hover {
  background: var(--brand-2);
}

.btn.secondary {
  background: var(--panel-2);
  color: var(--ink);
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  min-height: 30px;
  padding: 6px 10px;
  font-size: 13px;
}

.message-layout {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  min-height: 620px;
}

.message-list {
  border-right: 1px solid var(--line);
  overflow: auto;
  max-height: calc(100vh - 220px);
}

.message-row {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
}

.message-row:hover,
.message-row.active {
  background: #edf7f6;
}

.row-top,
.mail-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.from {
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date,
.meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.subject {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.snippet {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  background: #eef1e9;
  color: #40504a;
  border: 1px solid #dde5d8;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.reader {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(360px, 1fr);
}

.reader-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
}

.reader-head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
}

.attachment {
  color: var(--brand);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  text-decoration: none;
  font-size: 13px;
}

.mail-frame {
  width: 100%;
  min-height: 100%;
  border: 0;
  background: #fff;
}

.empty {
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.compose,
.admin-grid {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.compose-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.full {
  grid-column: 1 / -1;
}

.send-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.status {
  min-height: 22px;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

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

.users-table th,
.users-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

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

.domain-checks label {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }

  .sidebar-foot {
    margin-top: 0;
    margin-left: auto;
  }

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

  .message-layout {
    grid-template-columns: 1fr;
  }

  .message-list {
    max-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .toolbar,
  .compose-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
