:root {
  --bg-page: #020617;
  --bg-sidebar: #020617;
  --bg-main: #0b1120;
  --bg-card: #020617;
  --bg-soft: #111827;
  --accent: #3b82f6;
  --accent-soft: rgba(59,130,246,0.12);
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --border: #1f2937;
  --danger: #ef4444;
  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow-soft: 0 18px 45px rgba(15,23,42,0.8);
  --shadow-subtle: 0 8px 24px rgba(15,23,42,0.6);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --row-unread-bg: rgba(15,23,42,0.95);
}

:root[data-theme="light"] {
  --bg-page: #f3f4f6;
  --bg-sidebar: #ffffff;
  --bg-main: #f9fafb;
  --bg-card: #ffffff;
  --bg-soft: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: rgba(37,99,235,0.08);
  --text: #111827;
  --text-soft: #6b7280;
  --border: #e5e7eb;
  --danger: #b91c1c;
  --shadow-soft: 0 12px 32px rgba(15,23,42,0.15);
  --shadow-subtle: 0 6px 18px rgba(15,23,42,0.12);
  --row-unread-bg: rgba(219,234,254,0.8);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-page);
  color: var(--text);
  font-family: var(--font-sans);
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.app-shell {
  display: flex;
  width: 100%;
  max-width: 1320px;
  height: 100vh;
  padding: 18px;
  gap: 18px;
}

/* SIDEBAR */

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 16px;
}

.sidebar-header-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nmd-logo-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f9fafb, #60a5fa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #0f172a;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.4);
}

.sidebar-title-line1 {
  font-size: 15px;
  font-weight: 700;
}

.sidebar-title-line2 {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-title-line3 {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-soft);
  margin: 10px 4px 6px;
}

.folder-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  margin-inline: 2px;
  border-radius: 8px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.16s ease-out;
}

.folder-item:hover {
  background: var(--bg-soft);
  border-color: rgba(148,163,184,0.7);
  color: var(--text);
}

.folder-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(59,130,246,0.5);
}

/* Вихідні / Архів – підсвічені */
.folder-item.outbox {
  border-color: rgba(59,130,246,0.7);
  color: var(--accent);
}

.folder-item.outbox.active {
  background: var(--accent-soft);
  color: var(--text);
}

.folder-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(148,163,184,0.7);
}

.folder-item.active .folder-dot {
  background: var(--accent);
}

.folder-label {
  flex: 1;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.link-ghost {
  color: var(--text-soft);
  text-decoration: none;
  opacity: 0.7;
}

.link-ghost:hover {
  opacity: 1;
  text-decoration: underline;
}

/* MAIN PANEL */

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--bg-main);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border);
  padding: 12px;
  min-width: 0;
  min-height: 0;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 10px;
}

.top-bar-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.top-title {
  font-size: 17px;
  font-weight: 600;
}

.top-subtitle {
  font-size: 12px;
  color: var(--text-soft);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* BUTTONS */

.btn {
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.35);
  background: var(--bg-card);
  color: var(--text-soft);
  font-size: 12px;
  padding: 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease-out;
  text-decoration: none;
}

.btn:hover {
  border-color: rgba(209,213,219,0.9);
  color: var(--text);
  background: var(--bg-soft);
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #22c1c3);
  border-color: rgba(191,219,254,0.9);
  color: #f9fafb;
  box-shadow: 0 10px 28px rgba(37,99,235,0.6);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 34px rgba(37,99,235,0.9);
}

.btn-danger {
  border-color: rgba(248,113,113,0.7);
  color: #fecaca;
}

.btn-danger:hover {
  background: rgba(127,29,29,0.9);
  color: #fee2e2;
}

/* MAIL LAYOUT */

.mail-layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.mail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 2px;
  border-bottom: 1px solid var(--border);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-counter {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-soft);
}

.mail-content {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 10px;
  padding-top: 6px;
}

.mail-list-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mail-preview-panel {
  width: 42%;
  min-width: 280px;
  max-width: 480px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-subtle);
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-list-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-subtle);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mail-table-wrapper {
  flex: 1;
  overflow: auto;
}

table.mail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 520px;
}

.mail-table thead {
  background: var(--bg-soft);
  position: sticky;
  top: 0;
  z-index: 2;
}

.mail-table th,
.mail-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.mail-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
}

.mail-table tbody tr {
  cursor: pointer;
  transition: background 0.12s ease-out;
}

.mail-table tbody tr:hover {
  background: var(--bg-soft);
}

.mail-table tbody tr.is-selected {
  background: var(--accent-soft);
}

.mail-table tbody tr.is-unread td {
  font-weight: 600;
  background: var(--row-unread-bg);
}

.col-select {
  width: 30px;
}
.col-from {
  width: 160px;
}
.col-subject {
  width: auto;
}
.col-date {
  width: 130px;
  text-align: right;
  color: var(--text-soft);
  font-size: 11px;
}

.row-empty td {
  text-align: center;
  color: var(--text-soft);
  padding: 16px;
}

/* PREVIEW */

.preview-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.preview-badge-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-soft);
}

.badge-soft {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.4);
  background: var(--bg-soft);
}

.preview-subject {
  font-size: 14px;
  font-weight: 600;
}
.preview-meta {
  font-size: 11px;
  color: var(--text-soft);
}

.preview-body {
  flex: 1;
  margin-top: 6px;
  padding: 8px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.preview-footer {
  margin-top: 6px;
  font-size: 11px;
}

.attachments-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.attachments-list li a {
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
}

.attachments-list li a:hover {
  text-decoration: underline;
}

.preview-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  font-size: 12px;
  text-align: center;
  padding: 12px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.4);
  font-size: 11px;
  color: var(--text-soft);
}

.tag-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #22c55e;
}

/* AUTH */

.auth-wrapper {
  margin: 40px auto;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-soft);
}

.auth-wrapper h1 {
  margin-top: 0;
  margin-bottom: 10px;
}

.auth-wrapper input[type="text"],
.auth-wrapper input[type="password"] {
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text);
  padding: 7px 10px;
  margin-top: 2px;
  margin-bottom: 8px;
  font-size: 13px;
}

.auth-wrapper button {
  width: 100%;
  border-radius: 999px;
  border: none;
  padding: 8px 12px;
  background: linear-gradient(135deg, #3b82f6, #22c1c3);
  color: #f9fafb;
  font-size: 13px;
  cursor: pointer;
  margin-top: 6px;
}

.auth-wrapper button:hover {
  box-shadow: 0 10px 28px rgba(37,99,235,0.6);
}

.auth-wrapper a {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
}

.auth-wrapper a:hover {
  text-decoration: underline;
}

.error {
  color: #fecaca;
  font-size: 12px;
  margin-top: 6px;
}

.success {
  color: #bbf7d0;
  font-size: 12px;
  margin-top: 6px;
}

/* RECIPIENT PICKER */

.recipient-picker {
  margin-top: 10px;
  padding: 8px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 12px;
}

.recipient-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
  min-height: 22px;
}

.recipient-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.5);
  background: var(--bg-soft);
  font-size: 11px;
}

.recipient-pill span.type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a5b4fc;
}

.recipient-pill button {
  border: none;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  font-size: 11px;
}

.recipient-pill button:hover {
  color: #fca5a5;
}

.recipient-search-input {
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  margin-bottom: 4px;
}

.recipient-suggestions {
  max-height: 160px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.recipient-suggestion-item {
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.recipient-suggestion-item:hover {
  background: var(--accent-soft);
}

.suggest-main {
  font-size: 12px;
}
.suggest-sub {
  font-size: 11px;
  color: var(--text-soft);
}
.suggest-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  margin-right: 6px;
}
