/* ===========================================================================
   PQCMail — UI theme. Dark, Outlook-inspired, three-pane.
   =========================================================================== */
:root {
  --bg: #0e1119;
  --panel: #161b27;
  --panel-2: #1e2536;
  --panel-3: #28304557;
  --rail: #12161f;
  --text: #e7ebf4;
  --text-dim: #b6bed2;
  --muted: #818aa3;
  --accent: #3b82f6;
  --accent-2: #6ea8ff;
  --accent-soft: #3b82f622;
  --ok: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --border: #262e40;
  --border-soft: #20283a;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 6px 24px -8px rgba(0,0,0,.55);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-soft); }

/* ---- inline svg icons ---- */
.ic { width: 18px; height: 18px; flex: none; }

/* ---- avatar ---- */
.avatar {
  --h: 210; flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; font-weight: 600; font-size: .9rem;
  color: #fff; letter-spacing: .01em; user-select: none;
  background: linear-gradient(135deg, hsl(var(--h) 62% 52%), hsl(calc(var(--h) + 26) 60% 42%));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.avatar.sm { width: 26px; height: 26px; font-size: .72rem; }
.avatar.lg { width: 46px; height: 46px; font-size: 1.05rem; }

/* ---- top bar ---- */
.topbar {
  flex: 0 0 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: linear-gradient(90deg, #11203b, #14182400 60%), var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 1.06rem; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.tag {
  font-size: .6rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent-2); padding: 3px 9px; border-radius: 999px;
  border: 1px solid #3b82f655;
}
#nav { display: flex; align-items: center; gap: 12px; }
.who { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: .85rem; }
.who span { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- buttons ---- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; transition: .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  cursor: pointer; font: inherit; font-weight: 500; transition: .15s;
}
.btn:hover { border-color: var(--accent); background: var(--panel-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2f74e6; box-shadow: 0 4px 14px -4px var(--accent); }
.btn.primary:disabled { background: var(--panel-2); border-color: var(--border); color: var(--muted); cursor: not-allowed; box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: .82rem; }
button.btn:not(.small):not(.compose-btn) { width: 100%; justify-content: center; margin-top: 8px; }
.btn .ic { width: 16px; height: 16px; }

a { color: var(--accent-2); cursor: pointer; text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: .8rem; } .center { text-align: center; }
.pad { padding: 18px; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.error { background: rgba(248,113,113,.1); border: 1px solid #f8717155; color: #fca5a5;
  padding: 10px 12px; border-radius: var(--radius-sm); margin: 10px 0; font-size: .88rem; }
.notice { background: var(--accent-soft); border: 1px solid #3b82f655; color: var(--text-dim);
  padding: 10px 12px; border-radius: var(--radius-sm); margin: 12px 0; font-size: .9rem; }
.reccode { font-family: var(--mono); font-size: 1.05rem; letter-spacing: .03em; line-height: 1.8;
  background: var(--bg); border: 1px solid var(--accent); border-radius: var(--radius-sm);
  padding: 14px; margin: 12px 0; text-align: center; color: var(--accent-2); user-select: all; word-break: break-word; }
textarea { resize: vertical; font-family: var(--mono); }

#app { flex: 1; min-height: 0; }

/* ---- auth ---- */
.authwrap { height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.card.auth { width: 410px; max-width: 100%; }
h1 { margin: 0 0 14px; font-size: 1.45rem; font-weight: 650; letter-spacing: -.02em; }
label { display: block; margin: 14px 0; font-size: .8rem; font-weight: 500; color: var(--text-dim); }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text);
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=file] { padding: 9px; }
input[type=number] { width: 100%; }

/* ---- three-pane mail grid ---- */
.mailgrid { display: grid; grid-template-columns: 244px 360px 1fr; height: 100%; }

/* rail */
.rail { background: var(--rail); border-right: 1px solid var(--border); padding: 14px 12px;
  overflow-y: auto; display: flex; flex-direction: column; }
.compose-btn { width: 100%; justify-content: center; gap: 8px; padding: 11px;
  background: var(--accent); border: none; color: #fff; font-weight: 600; border-radius: var(--radius-sm);
  cursor: pointer; font: inherit; font-weight: 600; display: inline-flex; align-items: center; margin-bottom: 16px;
  transition: .15s; }
.compose-btn:hover { background: #2f74e6; box-shadow: 0 4px 14px -4px var(--accent); }
.compose-btn .ic { width: 17px; height: 17px; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; font-size: .9rem; font-weight: 500; position: relative;
  transition: background .12s, color .12s;
}
.folder:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.folder.active { background: var(--accent-soft); color: var(--accent-2); }
.folder.active::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent); }
.folder .ic { width: 17px; height: 17px; opacity: .85; }
.f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f-count { font-size: .7rem; font-weight: 600; color: var(--muted); background: var(--panel-2);
  padding: 1px 8px; border-radius: 999px; }
.folder.active .f-count { background: #3b82f633; color: var(--accent-2); }
.f-del { opacity: 0; border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 2px; border-radius: 4px; display: inline-flex; transition: .12s; }
.f-del .ic { width: 14px; height: 14px; }
.folder:hover .f-del { opacity: 1; }
.f-del:hover { color: var(--bad); background: #f8717122; }
.folders-head { display: flex; align-items: center; justify-content: space-between;
  margin: 18px 4px 6px; font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); }
.folders-head .icon-btn { width: 24px; height: 24px; }
.folders-head .ic { width: 15px; height: 15px; }
.rail-empty { color: var(--muted); font-size: .8rem; padding: 4px 11px; margin: 0; }
.rail-foot { margin-top: auto; padding-top: 14px; }
.acct { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: var(--radius-sm); background: var(--panel-2); }
.acct-mail { font-size: .76rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buildinfo { margin-top: 12px; font-size: .68rem; color: var(--muted); word-break: break-all; line-height: 1.6; }
.buildinfo code { font-family: var(--mono); font-size: .68rem; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* message list */
.listcol { border-right: 1px solid var(--border); overflow-y: auto; background: var(--panel); }
.list-head { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border); display: flex; align-items: baseline; justify-content: space-between; }
.list-head h2 { margin: 0; font-size: 1.18rem; font-weight: 650; letter-spacing: -.01em; }
.listrows { display: flex; flex-direction: column; }
.row { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; position: relative; transition: background .12s; }
.row:hover { background: var(--panel-2); }
.row.sel { background: var(--panel-3); }
.row.sel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.row-main { flex: 1; min-width: 0; }
.row-l1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row-from { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { color: var(--muted); font-size: .74rem; flex: none; }
.row-l2 { display: flex; align-items: center; gap: 6px; margin: 2px 0 5px; }
.row-subj { color: var(--text-dim); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.row-l3 { display: flex; align-items: center; gap: 7px; }
.m-clip { color: var(--muted); display: inline-flex; }
.m-clip .ic { width: 15px; height: 15px; }
.row.unread .row-from, .row.unread .row-subj { color: var(--text); font-weight: 700; }
.row.unread::after { content: ""; position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.pill { font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 999px; }
.pill.bad { background: #f8717122; color: #fca5a5; }
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 70px 20px; color: var(--muted); text-align: center; }
.empty .ic { width: 40px; height: 40px; opacity: .4; }
.empty p { margin: 0; font-size: .9rem; }

/* reading pane */
.readcol { overflow-y: auto; background: var(--bg); }
.readempty { height: 100%; display: flex; align-items: center; justify-content: center; }
.readbody { max-width: 840px; padding: 24px 30px; }
.readbar { display: flex; gap: 6px; margin-bottom: 18px; align-items: center; flex-wrap: wrap; }
.readtools { display: flex; gap: 6px; margin: 14px 0; flex-wrap: wrap; }
.tool { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel); color: var(--text-dim); cursor: pointer;
  font: inherit; font-size: .84rem; font-weight: 500; transition: .15s; }
.tool:hover { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.tool .ic { width: 16px; height: 16px; }
.movewrap { position: relative; }
.movemenu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 5; min-width: 190px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column; gap: 2px; }
.movemenu[hidden] { display: none; }
.movemenu .mv { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: none;
  background: transparent; color: var(--text-dim); cursor: pointer; font: inherit; font-size: .85rem;
  border-radius: 5px; text-align: left; width: 100%; }
.movemenu .mv:hover { background: var(--panel-2); color: var(--text); }
.movemenu .ic { width: 16px; height: 16px; opacity: .8; }
.readhead { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.readhead-t { min-width: 0; }
.readsub { font-size: 1.5rem; margin: 0 0 4px; font-weight: 650; letter-spacing: -.02em; line-height: 1.25; }
.readfrom { color: var(--text-dim); font-size: .9rem; }
.msghead { color: var(--text-dim); font-size: .86rem; display: grid; gap: 5px;
  padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.msghead strong { color: var(--muted); font-weight: 600; }
iframe.msgbody { width: 100%; height: 340px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: transparent; display: block; }
.watermarked { position: relative; }
.watermarked::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background: repeating-linear-gradient(-30deg, transparent 0 60px, rgba(138,148,173,.04) 60px 61px); }

/* labels */
.label { display: inline-block; font-size: .64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: 2px 9px; border-radius: 999px; }
.label-internal { background: #243049; color: #9fb3d8; }
.label-confidential { background: #43370f; color: var(--warn); }
.label-secret { background: #45191e; color: #f78a92; }

/* rich-text editor */
.compose .cfield { margin: 12px 0; }
.rtbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 12px 0 0;
  padding: 7px; background: var(--panel-2); border: 1px solid var(--border);
  border-bottom: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.rtbar button { padding: 5px 11px; min-width: 32px; border: 1px solid transparent; background: transparent;
  color: var(--text); border-radius: 5px; cursor: pointer; font: inherit; }
.rtbar button:hover { background: var(--panel); border-color: var(--border); }
.rtbar select { width: auto; margin: 0; padding: 5px 7px; }
.rtbody { min-height: 180px; max-height: 340px; overflow-y: auto; padding: 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  line-height: 1.6; outline: none; }
.rtbody:focus { border-color: var(--accent); }
.policyrow { display: flex; gap: 12px; margin-top: 14px; }
.policyrow label { flex: 1; }

/* attachments & audit */
.atts { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.atts-h { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: .9rem; color: var(--text-dim); }
.atts-h .ic { width: 16px; height: 16px; }
.atts ul { list-style: none; padding: 0; margin: 10px 0 0; }
.atts li { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.crypto { margin-top: 20px; font-size: .82rem; color: var(--muted); }
.crypto summary { cursor: pointer; user-select: none; }
.crypto summary:hover { color: var(--text-dim); }
.crypto ul { margin: 8px 0 0; }
.audit { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .82rem; }
.audit th, .audit td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border); }
.audit th { color: var(--muted); font-weight: 600; }
.fp { font-family: var(--mono); font-size: .82rem; background: var(--panel-2); padding: 2px 7px; border-radius: 5px; }

/* viewer overlay */
.viewer-overlay { position: fixed; inset: 0; background: rgba(6,9,16,.95); z-index: 1000;
  display: flex; flex-direction: column; backdrop-filter: blur(2px); }
.viewer { display: flex; flex-direction: column; height: 100%; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; padding: 11px 18px;
  background: var(--panel); border-bottom: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.viewer-body { flex: 1; overflow: auto; padding: 20px; text-align: center; user-select: none; }
.viewer-body canvas { max-width: 100%; margin: 0 auto 16px; display: block;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff;
  box-shadow: 0 8px 30px -12px rgba(0,0,0,.6); }

/* password strength meter */
.pwmeter { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin: 8px 0 6px; }
.pwbar { height: 100%; width: 0; border-radius: 4px; transition: width .25s, background .25s; }
.pwbar.s0, .pwbar.s1 { background: var(--bad); }
.pwbar.s2 { background: var(--warn); }
.pwbar.s3, .pwbar.s4 { background: var(--ok); }
.pwrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.pwfb { font-size: .78rem; color: var(--muted); }
.pwactions { display: flex; align-items: center; gap: 12px; flex: none; }
.pwshow { margin: 0; font-size: .78rem; display: flex; align-items: center; gap: 5px; color: var(--muted); }
.pwshow input { width: auto; margin: 0; }
.pwactions .btn.small { margin: 0; }

/* scrollbars */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #2c3650; border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #3a466690; background-clip: content-box; border: 3px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- responsive: collapse to a workable layout on narrow screens ---- */
@media (max-width: 980px) {
  .mailgrid { grid-template-columns: 64px 300px 1fr; }
  .compose-btn span, .f-name, .f-count, .folders-head span, .rail-empty, .acct-mail, .buildinfo { display: none; }
  .compose-btn { padding: 11px 0; }
  .folder { justify-content: center; padding: 11px 0; }
  .rail-foot { display: flex; justify-content: center; }
}
@media (max-width: 680px) {
  .mailgrid { grid-template-columns: 64px 1fr; }
  .readcol { display: none; }
}
