/* ============ TeamMail ============ */
* { box-sizing: border-box; }
:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --green: #16a34a;
  --amber: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
}
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #0f172a; color: #e2e8f0; padding: 0 16px; height: 48px; flex: 0 0 auto;
}
.topbar-left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.logo { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: #cbd5e1; padding: 6px 12px; border-radius: 6px; font-weight: 500;
}
.topbar nav a:hover { background: #1e293b; text-decoration: none; }
.topbar nav a.active { background: var(--accent); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-right .whoami { font-weight: 600; }
.topbar-right a { color: #94a3b8; }
.btn-link {
  background: none; border: none; color: #94a3b8; cursor: pointer; font: inherit; padding: 0;
}
.btn-link:hover { color: #fff; }

/* ---------- flashes & toasts ---------- */
.flash { padding: 10px 14px; margin: 10px 16px; border-radius: 8px; font-weight: 500; }
.flash-ok { background: #dcfce7; color: #14532d; }
.flash-error { background: #fee2e2; color: #7f1d1d; }
.flash code { background: rgba(0,0,0,.08); padding: 1px 6px; border-radius: 4px; font-size: 13px; user-select: all; }
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow);
  max-width: 380px; animation: slide-in .18s ease-out;
}
.toast.err { background: var(--danger); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-block; background: #fff; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn[disabled] { opacity: .55; cursor: default; }
label { display: block; margin: 10px 0; font-weight: 600; font-size: 13px; }
input, select, textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
details summary { cursor: pointer; font-weight: 600; margin: 10px 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 130px; gap: 0 12px; }

/* ---------- auth / installer ---------- */
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  padding: 32px; width: 100%; max-width: 400px;
}
.auth-card-wide { max-width: 560px; }
.auth-card h1 { margin: 4px 0 2px; font-size: 22px; }
.auth-card h2.step { font-size: 15px; color: var(--muted); margin: 14px 0 10px; }
.auth-logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 22px; margin-bottom: 10px;
}
.auth-card .flash { margin: 10px 0; }

/* ---------- admin ---------- */
.admin-main { padding: 18px; max-width: 1200px; margin: 0 auto; width: 100%; overflow-y: auto; }
.admin-grid { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table.small td, .table.small th { padding: 5px 6px; font-size: 12.5px; }
.row-disabled td { opacity: .5; }
.actions form { margin-bottom: 4px; }
.tag { display: inline-block; border-radius: 20px; padding: 1px 9px; font-size: 11.5px; font-weight: 600; background: #e2e8f0; }
.tag-green { background: #dcfce7; color: #166534; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tag-amber { background: #fef3c7; color: #92400e; }
.tag-blue { background: #dbeafe; color: #1e40af; }
.mb-block { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.mb-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.mb-servers { margin-left: auto; }
.assign-form input { padding: 5px 8px; }
.row-actions { margin-top: 10px; display: flex; gap: 8px; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-bar select { width: auto; margin-top: 0; }
.audit-details { max-width: 480px; overflow-wrap: anywhere; }
.pager { display: flex; gap: 6px; margin-top: 12px; }
.pager a, .pager .cur { padding: 3px 9px; border-radius: 6px; }
.pager .cur { background: var(--accent); color: #fff; }
.empty-state { text-align: center; margin: 80px auto; color: var(--muted); }

/* ---------- mail app layout ---------- */
.mail-app {
  flex: 1; display: grid; grid-template-columns: 230px 380px 1fr;
  min-height: 0; background: var(--bg); gap: 0;
}
.pane { min-height: 0; display: flex; flex-direction: column; }

/* folders pane */
.pane-folders { background: #e8edf4; border-right: 1px solid var(--border); padding: 12px 10px; overflow-y: auto; }
.mb-switch { margin-bottom: 10px; }
.mb-switch select { background: #fff; font-weight: 600; }
.compose-btn { width: 100%; margin-bottom: 12px; padding: 10px; font-size: 14px; border-radius: 10px; }
.folder-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border-radius: 8px; cursor: pointer; border: none; background: none;
  font: inherit; text-align: left; color: var(--text);
}
.folder-item:hover { background: #dbe4ee; }
.folder-item.active { background: var(--accent); color: #fff; }
.folder-item.active .badge { background: rgba(255,255,255,.25); color: #fff; }
.folder-item .f-icon { width: 18px; text-align: center; flex: 0 0 auto; }
.folder-item .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  background: var(--accent); color: #fff; border-radius: 20px; font-size: 11px; font-weight: 700;
  padding: 1px 7px; flex: 0 0 auto;
}

/* list pane */
.pane-list { background: var(--panel); border-right: 1px solid var(--border); }
.list-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.list-head input[type=search] { margin: 0; flex: 1; }
.list-head .icon-btn { flex: 0 0 auto; }
.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  font-size: 15px; padding: 6px 9px; color: var(--muted); line-height: 1;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text); }
.msg-list { flex: 1; overflow-y: auto; }
.msg-row {
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; position: relative;
  display: flex; flex-direction: column; gap: 2px;
}
.msg-row:hover { background: #f8fafc; }
.msg-row.sel { background: #eff6ff; box-shadow: inset 3px 0 0 var(--accent); }
.msg-row .r1 { display: flex; align-items: baseline; gap: 8px; }
.msg-row .m-from { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row .m-date { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.msg-row .r2 { display: flex; align-items: baseline; gap: 8px; }
.msg-row .m-subject { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #334155; }
.msg-row.unread .m-from, .msg-row.unread .m-subject { font-weight: 700; color: var(--text); }
.msg-row.unread::before {
  content: ""; position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}
.msg-row .m-star { flex: 0 0 auto; cursor: pointer; color: #cbd5e1; }
.msg-row .m-star.on { color: #f59e0b; }
.msg-row .m-star:hover { color: #f59e0b; }
.list-foot {
  border-top: 1px solid var(--border); padding: 8px 12px; display: flex; align-items: center;
  justify-content: space-between; color: var(--muted); font-size: 12.5px;
}
.list-foot .pg { display: flex; gap: 4px; }
.list-empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* reading pane */
.pane-read { background: var(--bg); overflow-y: auto; }
.read-empty { display: flex; flex: 1; align-items: center; justify-content: center; color: #94a3b8; flex-direction: column; gap: 8px; }
.read-empty .big { font-size: 44px; }
.read-card { background: var(--panel); margin: 14px; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.read-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.read-head h2 { margin: 0 0 8px; font-size: 17px; overflow-wrap: anywhere; }
.read-meta { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.read-meta b { color: var(--text); }
.read-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.imgs-note {
  background: #fef9c3; color: #713f12; font-size: 12.5px; padding: 7px 18px;
  display: flex; gap: 10px; align-items: center;
}
.imgs-note button { flex: 0 0 auto; }
.read-body-wrap { padding: 6px 10px; }
.read-body-wrap iframe { width: 100%; border: none; display: block; background: #fff; }
.read-atts { padding: 10px 18px 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 20px; background: #f8fafc; font-size: 12.5px; color: var(--text);
}
.att-chip:hover { border-color: var(--accent); text-decoration: none; }
.att-chip .a-size { color: var(--muted); }

/* ---------- compose modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 200;
  display: flex; align-items: flex-end; justify-content: flex-end; padding: 20px;
}
.compose {
  background: var(--panel); border-radius: 14px 14px 0 0; box-shadow: 0 8px 40px rgba(0,0,0,.25);
  width: min(680px, 100%); max-height: calc(100vh - 60px); display: flex; flex-direction: column;
  border-radius: 14px;
}
.compose-head {
  background: #0f172a; color: #fff; padding: 10px 16px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; border-radius: 14px 14px 0 0;
}
.compose-head button { background: none; border: none; color: #94a3b8; font-size: 18px; cursor: pointer; }
.compose-head button:hover { color: #fff; }
.compose form { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 6px 16px 14px; }
.compose .c-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); gap: 8px; }
.compose .c-row > span { color: var(--muted); font-size: 12.5px; width: 52px; flex: 0 0 auto; }
.compose .c-row input { border: none; border-radius: 0; padding: 9px 2px; margin: 0; }
.compose .c-row input:focus { outline: none; }
.compose .cc-toggle { color: var(--accent); cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.compose textarea {
  border: none; border-radius: 0; resize: vertical; min-height: 200px; padding: 10px 2px; margin: 0;
  font: 14px/1.5 inherit;
}
.compose textarea:focus { outline: none; }
.compose-foot { display: flex; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.compose-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 2px; }
.compose-atts .att-chip .x { cursor: pointer; color: var(--muted); font-weight: 700; }
.compose-atts .att-chip .x:hover { color: var(--danger); }
.from-line { font-size: 12.5px; color: var(--muted); padding: 8px 2px 2px; }
.from-line b { color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .mail-app { grid-template-columns: 200px 1fr; }
  .pane-read { position: fixed; inset: 48px 0 0 0; z-index: 150; display: none; }
  .pane-read.open { display: flex; flex-direction: column; }
  .read-back { display: inline-flex !important; }
  .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .mail-app { grid-template-columns: 1fr; }
  .pane-folders {
    position: fixed; inset: 48px 30% 0 0; z-index: 160; display: none;
    box-shadow: var(--shadow);
  }
  .pane-folders.open { display: block; }
  .folders-toggle { display: inline-flex !important; }
  .topbar nav a { padding: 6px 8px; }
  .modal-back { padding: 0; }
  .compose { max-height: 100vh; border-radius: 0; }
}
.read-back, .folders-toggle { display: none; }
