:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e3e6ea;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #f6821f;
  --accent-dark: #d96f10;
  --ok: #1f9d55;
  --warn: #b7791f;
  --err: #d64545;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161a20;
    --panel-2: #1b2027;
    --border: #262c34;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err-text { color: var(--err); font-size: 13px; min-height: 18px; margin: 6px 0 0; }

input[type="text"], input[type="password"], select {
  width: 100%; padding: 10px 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
button { font-family: inherit; }
.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 10px 18px; font-size: 14px; font-weight: 650; cursor: pointer; transition: background .15s;
}
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: .6; cursor: default; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; }
.link-btn:hover { color: var(--accent-dark); text-decoration: underline; }
.icon-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
.brand.big h1 { font-size: 20px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); }
.badge { font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px; }
.badge.small { font-size: 11px; }

/* Login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card .primary { margin-top: 4px; }

/* App layout */
.app { display: grid; grid-template-columns: 220px 340px 1fr; height: 100vh; overflow: hidden; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 16px 14px; display: flex; flex-direction: column; gap: 16px;
}
.compose-btn { width: 100%; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folders button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: none; border: none; color: var(--text); text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.folders button:hover { background: var(--panel-2); }
.folders button.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 650; }
.folders .count { font-size: 12px; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.folders button.active .count { background: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }

.list-col { background: var(--panel-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.list-head { padding: 14px; border-bottom: 1px solid var(--border); }
.list { overflow-y: auto; flex: 1; }
.list-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 11px 14px 11px 30px;
  border-bottom: 1px solid var(--border); cursor: pointer; position: relative;
}
.list-item:hover { background: var(--panel); }
.list-item.active { background: var(--panel); }
.list-item.unread .li-from, .list-item.unread .li-subject { font-weight: 700; }
.list-item .li-from { font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-date { font-size: 12px; color: var(--muted); }
.list-item .li-subject { font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-snippet { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .unread-dot { position: absolute; left: 14px; top: 17px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.list-item .flags { display: flex; gap: 6px; }
.list-item .star { color: var(--accent); }
.empty-list { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.read-col { background: var(--panel); overflow-y: auto; min-width: 0; }
.empty-state { display: grid; place-items: center; height: 100%; color: var(--muted); }
.read-head { padding: 20px 24px 14px; border-bottom: 1px solid var(--border); }
.read-subject { font-size: 19px; font-weight: 700; margin: 0 0 10px; }
.read-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.read-meta .who { color: var(--text); font-weight: 600; }
.read-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.read-actions .act {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--text);
}
.read-actions .act:hover { border-color: var(--accent); color: var(--accent); }
.read-body { padding: 18px 24px; }
.read-body img { max-width: 100%; }
.read-body .plain { white-space: pre-wrap; word-wrap: break-word; font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.read-iframe { width: 100%; border: none; min-height: 420px; }
.att-list { margin: 0 24px 18px; display: flex; flex-direction: column; gap: 6px; }
.att-list a { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); text-decoration: none; font-size: 13px; }
.att-list a:hover { border-color: var(--accent); }
.att-list .sz { color: var(--muted); margin-left: auto; }
.thread-strip { padding: 10px 24px; border-bottom: 1px solid var(--border); font-size: 12.5px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }

/* Compose modal */
.modal { position: fixed; inset: 0; background: rgba(10,12,16,.5); display: grid; place-items: center; padding: 24px; z-index: 50; }
.modal-card { width: min(720px, 100%); max-height: 92vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15px; margin: 0; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.from-inputs { display: flex; gap: 10px; flex-wrap: wrap; }
.from-inputs #c-name { flex: 1 1 160px; }
.addr-group { flex: 2 1 300px; display: flex; align-items: center; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.addr-group:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.addr-group input { border: none; background: transparent; box-shadow: none !important; }
.addr-group .at { color: var(--muted); padding: 0 2px; }
.toggle-row { display: flex; gap: 14px; }
.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); } .status.err { color: var(--err); }

.attachments { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px dashed var(--border); padding-top: 12px; }
.file-btn { display: inline-flex; padding: 7px 13px; font-size: 13px; font-weight: 600; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.file-btn:hover { border-color: var(--accent); color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); }
#c-file-list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
#c-file-list li { display: flex; justify-content: space-between; align-items: center; font-size: 13px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
#c-file-list .rm { background: none; border: none; color: var(--err); cursor: pointer; }

#editor-wrap .ql-toolbar.ql-snow { border-color: var(--border); background: var(--panel-2); border-radius: 8px 8px 0 0; }
#editor-wrap .ql-container.ql-snow { border-color: var(--border); border-radius: 0 0 8px 8px; font-size: 14px; }
#editor-wrap .ql-editor { min-height: 200px; }
.ql-snow .ql-stroke { stroke: var(--muted); } .ql-snow .ql-fill { fill: var(--muted); } .ql-snow .ql-picker { color: var(--muted); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); z-index: 60; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .folders { flex-direction: row; } .sidebar-foot { margin: 0; flex-direction: row; }
  .list-col, .read-col { display: none; }
  .app.show-list .list-col { display: flex; }
  .app.show-read .read-col { display: block; }
}
