/* ==========================================================================
   Mail Control Panel — arttadmori.org
   ========================================================================== */

:root {
  --bg:            #0f1419;
  --bg-elevated:   #161c24;
  --bg-card:       #1b232d;
  --bg-input:      #111820;
  --border:        #2a3542;
  --border-soft:   #222c37;

  --text:          #e6edf3;
  --text-muted:    #8b98a5;
  --text-dim:      #5f6b78;

  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --accent-soft:   rgba(59, 130, 246, 0.12);

  --green:         #22c55e;
  --green-soft:    rgba(34, 197, 94, 0.12);
  --amber:         #f59e0b;
  --amber-soft:    rgba(245, 158, 11, 0.12);
  --red:           #ef4444;
  --red-soft:      rgba(239, 68, 68, 0.12);

  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 4px 16px rgba(0, 0, 0, 0.3);
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                   "Helvetica Neue", Arial, sans-serif;
  --mono:          ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
                   "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

.mono { font-family: var(--mono); font-size: 0.92em; }
.small { font-size: 0.85em; }
.strong { font-weight: 600; }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ==========================================================================
   Layout
   ========================================================================== */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-icon { font-size: 24px; }

.brand-name {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-domain {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
}

.nav a:hover {
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
  opacity: 0.9;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border-soft);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-dim); }

.logout {
  display: block;
  text-align: center;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
}

.logout:hover {
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 30px 60px;
  overflow-x: hidden;
}

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

.topbar h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

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

/* ==========================================================================
   Cards & grids
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

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

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.card-intro { color: var(--text-muted); font-size: 13px; margin: 0 0 12px; }
.card-foot { color: var(--text-dim); font-size: 12.5px; margin: 12px 0 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}

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

@media (max-width: 900px) {
  .grid-webmail { grid-template-columns: 1fr; }
  .sidebar { width: 68px; }
  .brand-name, .brand-domain, .nav a span:not(.nav-icon),
  .user-meta, .logout { display: none; }
  .nav a { justify-content: center; }
}

/* ==========================================================================
   Stats
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card-link { color: var(--text); }
.stat-card-link:hover { border-color: var(--accent); text-decoration: none; }

.stat-warn { border-color: rgba(245, 158, 11, 0.4); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stat-value {
  font-size: 27px;
  font-weight: 660;
  letter-spacing: -0.03em;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}

.stat-foot { font-size: 12px; color: var(--text-dim); }

/* ==========================================================================
   Status list
   ========================================================================== */
.status-list { list-style: none; margin: 0; padding: 0; }

.status-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.status-row:last-child { border-bottom: none; }

.status-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }

.status-name { font-weight: 560; font-size: 13.5px; }
.status-desc { font-size: 12px; color: var(--text-dim); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-ok { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot-bad { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

.status-state {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 20px;
}

.state-ok { color: var(--green); background: var(--green-soft); }
.state-bad { color: var(--red); background: var(--red-soft); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-full { font-size: 13px; }
.table-scroll { overflow-x: auto; }

.table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-dim);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 620;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.018); }

.actions-cell { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ==========================================================================
   Badges & pills
   ========================================================================== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-ok { color: var(--green); background: var(--green-soft); border-color: transparent; }
.badge-off { color: var(--text-dim); background: var(--bg-input); }
.badge-warn { color: var(--amber); background: var(--amber-soft); border-color: transparent; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
}

.pill-muted { background: var(--bg-input); color: var(--text-muted); }

/* ==========================================================================
   Usage bar
   ========================================================================== */
.usage { display: flex; flex-direction: column; gap: 4px; }

.usage-bar {
  height: 5px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.usage-warn { background: var(--amber); }

.usage-text { font-size: 11.5px; color: var(--text-dim); font-family: var(--mono); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-elevated); border-color: #3a4654; text-decoration: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { color: var(--red); border-color: rgba(239, 68, 68, 0.35); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }

.btn-small { padding: 4px 10px; font-size: 12px; }

.btn-block { width: 100%; }

/* ==========================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.field-hint { font-size: 11.5px; color: var(--text-dim); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select {
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.field-wide { grid-column: 1 / -1; }
.field-actions { justify-content: flex-end; }

.create-panel { display: none; }
.create-panel.open { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar-filter select { width: auto; min-width: 170px; }
.search-input { min-width: 280px; flex: 1; max-width: 460px; }

/* ==========================================================================
   Flash messages
   ========================================================================== */
.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 9px; }

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  border: 1px solid transparent;
}

.flash-icon { font-weight: 700; }

.flash-success { background: var(--green-soft); color: var(--green); border-color: rgba(34, 197, 94, 0.3); }
.flash-error { background: var(--red-soft); color: var(--red); border-color: rgba(239, 68, 68, 0.3); }

.flash-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  padding: 0 2px;
}

.flash-close:hover { opacity: 1; }

/* ==========================================================================
   Notices
   ========================================================================== */
.notice {
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fbbf24;
  padding: 13px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 13.5px;
}

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 26px 16px;
  margin: 0;
  font-size: 13.5px;
}

.link { font-size: 12.5px; font-weight: 550; }

/* ==========================================================================
   DNS page
   ========================================================================== */
.dns-block { margin-bottom: 12px; }

.dns-label {
  display: block;
  font-size: 11.5px;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.dns-value {
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

.dns-expected { color: var(--green); border-color: rgba(34, 197, 94, 0.25); }

.dns-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  padding-left: 12px;
  border-left: 2px solid var(--amber);
}

/* ==========================================================================
   Logs
   ========================================================================== */
.log-view {
  margin: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
  max-height: 66vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==========================================================================
   Settings grid
   ========================================================================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px;
}

.setting {
  display: flex;
  gap: 12px;
  padding: 9px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  font-size: 12.5px;
}

.setting-key {
  font-weight: 620;
  color: var(--text-muted);
  min-width: 76px;
  flex-shrink: 0;
}

.setting-val { color: var(--text); }

/* ==========================================================================
   Webmail
   ========================================================================== */
.folder-list ul { list-style: none; margin: 0; padding: 0; }

.folder-list li a {
  display: flex;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
}

.folder-list li a:hover { background: var(--bg-input); color: var(--text); text-decoration: none; }
.folder-list li a.active { background: var(--accent-soft); color: var(--accent); }

.folder-count {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-input);
  padding: 0 7px;
  border-radius: 10px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.open { display: flex; }

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h3 { margin: 0; font-size: 16px; font-weight: 620; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.modal-text { font-size: 13.5px; color: var(--text-muted); margin: 0 0 16px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 18px;
}

.modal-card .field { margin-bottom: 12px; }

@media (max-width: 700px) {
  .main { padding: 20px 14px 40px; }
  .table { min-width: 680px; }
  .toolbar-filter select, .toolbar > select { width: 100%; }
  .toolbar-filter { width: 100%; }
}

/* ==========================================================================
   Login page
   ========================================================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(59, 130, 246, 0.09), transparent 60%),
    var(--bg);
  padding: 20px;
}

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 34px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.login-head { text-align: center; margin-bottom: 24px; }

.login-logo { font-size: 38px; margin-bottom: 8px; }

.login-head h1 {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 640;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 12.5px;
  font-family: var(--mono);
}

.login-form { display: flex; flex-direction: column; gap: 15px; }
.login-form .btn { margin-top: 5px; padding: 10px; }

.login-foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin: 20px 0 0;
}

.login-card .flash { margin-bottom: 16px; }

/* ==========================================================================
   Error page
   ========================================================================== */
.error-card { text-align: center; padding: 44px 24px; }

.error-code {
  font-size: 54px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 10px;
}

.error-message { color: var(--text-muted); margin: 0 0 22px; font-size: 14px; }
