/* ============================================================
   SimpleMail v2.0.0 - единая тема веб-почты и админ-панели
   Палитра: камень + бирюзовый (teal). Без внешних зависимостей.
   ============================================================ */

:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #e2e8e4;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --ok: #15803d;
  --sidebar-bg: #1c2a2a;
  --sidebar-ink: #d7e2df;
  --sidebar-muted: #8ba39e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

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

code {
  background: rgba(15, 118, 110, 0.08);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.9em;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.h2 { font-size: 21px; }
.h3 { font-size: 15.5px; margin-bottom: 10px; }
.mt-6 { margin-top: 22px; }
.muted { color: var(--muted); }

/* ---------------------------------------------------------- layout */

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; flex-direction: column; gap: 6px; padding: 2px 6px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-mark.big { width: 52px; height: 52px; font-size: 20px; border-radius: 13px; }
.brand-name { font-size: 17px; font-weight: 700; color: #fff; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-muted); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--sidebar-muted);
  padding: 10px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--sidebar-ink);
  font-weight: 500;
  transition: background 0.15s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(15, 118, 110, 0.45); color: #fff; }

.sidebar-user {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-user-mail {
  font-size: 12.5px;
  color: var(--sidebar-ink);
  word-break: break-all;
  padding: 0 4px;
}

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 26px 28px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------------------------------------------------------- cards, stats */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat-value.ok { color: var(--ok); font-size: 20px; }
.stat-value.bad { color: var(--danger); font-size: 20px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-extra { font-size: 12.5px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: rgba(15, 118, 110, 0.06); border-color: var(--accent); color: var(--accent-dark); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(185, 28, 28, 0.35); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------------------------------------------------------- forms */

.form-col { display: flex; flex-direction: column; gap: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
  align-items: end;
}
.form-grid .h3 { grid-column: 1 / -1; margin-top: 6px; }
.form-grid .muted { grid-column: 1 / -1; margin: 0; font-size: 13px; }
.form-grid .toolbar { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink); }
.field-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field-checkbox span { font-weight: 500; }

.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
.input-sm { padding: 7px 10px; font-size: 13.5px; width: auto; }
textarea.input { resize: vertical; min-height: 120px; line-height: 1.55; }

.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; }

/* ---------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(15, 118, 110, 0.035); }
.table-sm td, .table-sm th { padding: 7px 8px; font-size: 13.5px; }

.mail-table { padding: 0; overflow: hidden; }
.mail-table table { table-layout: auto; }
.mail-table td, .mail-table th { padding: 9px 12px; }
.mail-table .col-flags { width: 52px; }
.mail-table .col-date { width: 120px; white-space: nowrap; }
.mail-table .col-size { width: 80px; white-space: nowrap; }
.mail-table .col-actions { width: 92px; text-align: right; white-space: nowrap; }
.mail-table .col-actions form { display: inline; }
.mail-table .col-from { max-width: 220px; }
.mail-table .col-from a { color: var(--ink); }
.mail-table .col-subject a { color: var(--ink); font-weight: 500; }
.mail-table tr.unread td { background: rgba(15, 118, 110, 0.05); }
.mail-table tr.unread .col-subject a { font-weight: 700; }
.mail-table tr.unread .col-from a { font-weight: 700; }
.mail-table tr.deleted td { opacity: 0.5; text-decoration: line-through; }
.row-off td { opacity: 0.55; }
.empty { text-align: center; color: var(--muted); padding: 26px !important; }
.flag { color: #b45309; font-weight: 700; }
.details { word-break: break-all; max-width: 380px; }

.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.pager { display: flex; align-items: center; gap: 10px; }
.pager-nav { display: inline-flex; gap: 6px; }

/* ---------------------------------------------------------- pills, badges, alerts */

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-dark);
  white-space: nowrap;
}
.pill-off { background: #e5e7eb; color: #6b7280; }
.pill-error { background: var(--danger-soft); color: var(--danger); }
.pill-delivery { background: #dcfce7; color: #166534; }
.pill-webmail { background: #ede9fe; color: #5b21b6; }
.pill-smtp { background: #ffedd5; color: #9a3412; }
.pill-imap { background: #d1fae5; color: #065f46; }
.pill-admin { background: #fde68a; color: #92400e; }

.lvl { font-size: 12px; font-weight: 700; }
.lvl-info { color: var(--muted); }
.lvl-warn { color: #b45309; }
.lvl-error { color: var(--danger); }

.alert {
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 14px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------------------------------------------------------- quota, progress */

.progress {
  height: 7px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  margin-top: 6px;
}
.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease;
}
.progress-bar.danger { background: var(--danger); }
.quota { padding: 14px 18px; }
.quota-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.quota-mini { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; white-space: nowrap; }

.folder-tools .inline-form { margin-bottom: 8px; }

/* ---------------------------------------------------------- login */

.center-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 400px; max-width: 100%; padding: 30px 28px; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .brand-mark { margin-bottom: 10px; }
.login-brand h1 { margin-top: 10px; font-size: 22px; }
.login-brand p { margin: 4px 0 0; }
.login-links { text-align: center; margin: 18px 0 0; font-size: 13px; }

/* ---------------------------------------------------------- messages (toasts) */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  max-width: 420px;
}
.toast {
  background: #1f2933;
  color: #f3f4f6;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.25);
  animation: toast-in 0.25s ease;
}
.toast-success { background: var(--accent-dark); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-warning { background: #b45309; color: #fff; }
.toast-info { background: #334155; color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------- message view */

.msg-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.msg-head { display: flex; flex-direction: column; gap: 10px; }
.msg-head .h2 { font-size: 19px; overflow-wrap: break-word; }
.msg-meta { display: flex; flex-direction: column; gap: 3px; font-size: 13.5px; }
.attachments { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.attachment {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 8px;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 12.5px;
}
.attachment:hover { background: #b5f2e4; text-decoration: none; }

.msg-body { padding: 0; overflow: hidden; }
.msg-iframe {
  width: 100%;
  height: 620px;
  border: none;
  display: block;
  background: #fff;
}
.msg-text {
  margin: 0;
  padding: 18px 20px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13.5px;
}

.compose-card { max-width: 860px; }

/* ---------------------------------------------------------- scrollbars */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(100, 116, 139, 0.55); }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); background-clip: content-box; }

/* ---------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .content { padding: 64px 14px 40px; }
  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .mail-table .col-date, .mail-table .col-size { display: none; }
}

@media (max-width: 560px) {
  .mail-table .col-from { max-width: 120px; }
  .msg-iframe { height: 480px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .btn { padding: 10px 14px; }
}
