/* ════════════════════════════════════════════════════════════
   COMMS_FORGE — emailgen.css  v5.0
   ════════════════════════════════════════════════════════════ */

/* ════ VARIABLES ════ */
:root {
  --bg:          #0a0a0a;
  --bg2:         #111111;
  --bg3:         #181818;
  --surface:     #141414;
  --surface2:    #1c1c1c;
  --border:      #272727;
  --border2:     #333333;
  --green:       #00ff88;
  --green-dim:   #00994d;
  --green-glow:  rgba(0,255,136,0.15);
  --amber:       #f6c050;
  --amber-dim:   #a07830;
  --red:         #ff4444;
  --red-dim:     #882222;
  --blue:        #4488ff;
  --text-bright: #e8e8e8;
  --text-mid:    #888888;
  --text-dim:    #444444;
  --text-muted:  #2a2a2a;
  --font-mono:   'Share Tech Mono', 'IBM Plex Mono', monospace;
  --font-display:'VT323', monospace;
  --font-plex:   'IBM Plex Mono', monospace;
  --sidebar-w:   248px;
  --sidebar-r:   268px;
  --header-h:    46px;
  --toolbar-h:   38px;
  --statusbar-h: 26px;
  --tr:          0.15s ease;
  --hl-color:    #f6c050;
}

/* ════ RESET ════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text-mid);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: default;
}

/* ════ SCROLLBARS ════ */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ════ CRT OVERLAY ════ */
.crt-overlay {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 9999;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,0,0,0.12) 2px, rgba(0,0,0,0.12) 4px
  );
  animation: scanRoll 10s linear infinite;
}
.crt-overlay.off { display: none; }

/* ════ NOISE OVERLAY ════ */
.noise-overlay {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 9998;
  opacity: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
  transition: opacity 0.3s;
}
.noise-overlay.active { opacity: 0.04; }

/* ════ HEADER ════ */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 200;
  box-shadow: 0 2px 20px rgba(0,0,0,0.6);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-logo {
  font-family: var(--font-display);
  font-size: 24px; letter-spacing: 4px;
  color: var(--green);
  text-shadow: 0 0 12px var(--green-glow), 0 0 24px rgba(0,255,136,0.04);
  line-height: 1;
}
.header-meta { display: flex; align-items: center; gap: 7px; }
.meta-tag { font-size: 9px; letter-spacing: 1.5px; color: var(--text-dim); text-transform: uppercase; }
.meta-tag.blink-slow { animation: blinkSlow 3s step-end infinite; }
.meta-sep { color: var(--border2); }

.header-center { display: flex; align-items: center; gap: 10px; }
.signal-bars { display: flex; gap: 3px; align-items: flex-end; height: 16px; }
.signal-bars span {
  width: 3px; border-radius: 1px; background: var(--green); opacity: 0.3;
}
.signal-bars span:nth-child(1) { height: 4px; }
.signal-bars span:nth-child(2) { height: 7px; }
.signal-bars span:nth-child(3) { height: 10px; }
.signal-bars span:nth-child(4) { height: 13px; }
.signal-bars span:nth-child(5) { height: 16px; }
.signal-bars span.active { opacity: 1; }
.signal-label { font-size: 9px; letter-spacing: 1.5px; color: var(--green-dim); }

.header-right { display: flex; align-items: center; gap: 6px; }
.hdr-btn {
  padding: 4px 9px;
  background: none; border: 1px solid var(--border2);
  color: var(--text-dim); font-family: var(--font-mono);
  font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  cursor: pointer; border-radius: 2px; transition: all var(--tr);
}
.hdr-btn:hover { border-color: var(--green); color: var(--green); background: rgba(0,255,136,0.04); }
.hdr-btn.active { border-color: var(--green-dim); color: var(--green-dim); }
.hdr-btn.accent { color: var(--green-dim); border-color: var(--green-dim); }
.hdr-btn.accent:hover { color: var(--green); border-color: var(--green); }

/* ════ APP SHELL ════ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-r);
  height: 100vh;
  padding-top: var(--header-h);
  overflow: hidden;
}

/* ════ SIDEBARS ════ */
.sidebar-left, .sidebar-right {
  background: var(--surface); border-color: var(--border);
  height: 100%; overflow-y: auto; overflow-x: hidden;
  padding: 10px 0;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
.sidebar-left  { border-right: 1px solid var(--border); }
.sidebar-right { border-left:  1px solid var(--border); }

.sidebar-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }

.section-label {
  font-size: 9px; letter-spacing: 2px;
  color: var(--green-dim); text-transform: uppercase;
  margin-bottom: 8px; font-family: var(--font-plex);
}

/* ── Template Cards ── */
.template-list { display: flex; flex-direction: column; gap: 5px; }
.tpl-card {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border: 1px solid var(--border);
  border-radius: 3px; cursor: pointer;
  transition: all var(--tr); background: var(--bg2);
}
.tpl-card:hover { border-color: var(--border2); background: var(--surface2); }
.tpl-card.active { border-color: var(--green); background: rgba(0,255,136,0.03); }
.tpl-card.active .tpl-name { color: var(--green); }

.tpl-preview {
  width: 34px; height: 26px; border-radius: 2px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.redacted-prev    { background: #fff; }
.arc-prev         { background: #fff; }
.bos-prev         { background: #fff; }
.signal-prev      { background: #0a1a0a; }
.classified-prev  { background: #f5f0e0; }
.ghost-prev       { background: #f8f8f8; }
.corp-prev        { background: #fff; }
.tx-prev          { background: #050808; }

.tpl-lines { display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 3px; }
.tpl-lines span { height: 2px; border-radius: 1px; background: #aaa; width: 30%; }
.tpl-lines span.long   { width: 80%; }
.tpl-lines span.med    { width: 55%; }
.tpl-lines span.short  { width: 20%; }
.tpl-lines span.thick  { height: 4px; width: 60%; background: #222; }
.tpl-lines span.dbl    { height: 3px; background: #cc4; }
.tpl-lines span.dashed { background: repeating-linear-gradient(90deg,#999 0,#999 3px,transparent 3px,transparent 6px); }
.tpl-lines span.fade   { background: #ccc; opacity: 0.3; }
.tpl-lines span.circle { border-radius: 50%; width: 14px; height: 14px; background: #666; }
.signal-prev .tpl-lines span { background: #0f0; opacity: 0.6; }
.tx-prev .tpl-lines span     { background: #0af; opacity: 0.5; }
.arc-prev .tpl-lines span    { background: #333; }
.bos-prev .tpl-lines span    { background: #111; }

.tpl-info { flex: 1; }
.tpl-name { font-size: 9px; font-weight: 600; color: var(--text-bright); letter-spacing: 1px; }
.tpl-sub  { font-size: 8px; color: var(--text-dim); display: none; }
.tpl-card.active .tpl-sub  { display: block; color: var(--green-dim); }

/* ── Classification Tags ── */
.tag-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tag-btn {
  padding: 5px 4px; background: var(--bg2); border: 1px solid var(--border);
  color: var(--text-dim); font-family: var(--font-mono);
  font-size: 8px; letter-spacing: 0.5px; cursor: pointer; border-radius: 2px;
  transition: all var(--tr); text-transform: uppercase;
}
.tag-btn:hover    { border-color: var(--border2); color: var(--text-mid); }
.tag-btn.active   { border-color: var(--green);  color: var(--green);  background: rgba(0,255,136,0.05); }
.tag-btn.red.active   { border-color: var(--red);   color: var(--red);   background: rgba(255,68,68,0.05); }
.tag-btn.amber.active { border-color: var(--amber); color: var(--amber); background: rgba(246,192,80,0.05); }

.class-indicator {
  margin-top: 6px; padding: 4px 8px; font-size: 9px;
  letter-spacing: 2px; text-align: center; border-radius: 2px;
  font-weight: bold; display: none;
}

/* ── Custom Classification Creator ── */
.custom-class-row {
  display: flex; gap: 4px; margin-top: 8px; align-items: center;
}
.custom-class-row input[type="text"] {
  flex: 1; font-size: 9px !important; padding: 4px 6px !important;
  text-transform: uppercase;
}
.custom-class-row input[type="color"] {
  width: 26px; height: 26px; flex-shrink: 0;
}
.custom-class-row button {
  padding: 4px 8px; background: var(--bg2); border: 1px solid var(--green-dim);
  color: var(--green-dim); font-family: var(--font-mono); font-size: 9px;
  cursor: pointer; border-radius: 2px; white-space: nowrap;
  transition: all var(--tr);
}
.custom-class-row button:hover { border-color: var(--green); color: var(--green); }

/* ── Priority ── */
.priority-row { display: flex; gap: 8px; align-items: center; margin-bottom: 5px; }
.pri-btn {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border2);
  background: none; color: var(--text-dim); font-size: 16px; line-height: 1;
  cursor: pointer; transition: all var(--tr);
  display: flex; align-items: center; justify-content: center;
}
.pri-btn.active         { color: var(--green);  border-color: var(--green);  box-shadow: 0 0 8px rgba(0,255,136,0.35); }
.pri-btn.amber.active   { color: var(--amber);  border-color: var(--amber);  box-shadow: 0 0 8px rgba(246,192,80,0.35); }
.pri-btn.red.active     { color: var(--red);    border-color: var(--red);    box-shadow: 0 0 8px rgba(255,68,68,0.35); }
.pri-btn.urgent.active  { color: #ff00ff; border-color: #ff00ff; box-shadow: 0 0 8px rgba(255,0,255,0.35); animation: urgentBlink 0.5s step-end infinite; }
.priority-label { font-size: 9px; letter-spacing: 2px; color: var(--text-dim); text-align: center; }

/* ── Highlight Style Buttons ── */
.hl-style-row { display: flex; gap: 4px; margin-top: 6px; margin-bottom: 4px; }
.hl-style-btn {
  padding: 3px 7px; background: var(--bg2); border: 1px solid var(--border);
  color: var(--text-dim); font-family: var(--font-mono); font-size: 8px;
  cursor: pointer; border-radius: 2px; transition: all var(--tr);
  letter-spacing: 0.5px;
}
.hl-style-btn:hover { border-color: var(--border2); color: var(--text-mid); }
.hl-style-btn.active { border-color: var(--amber); color: var(--amber); background: rgba(246,192,80,0.06); }

/* ── Controls ── */
.ctrl-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 5px;
}
.ctrl-label { font-size: 8px; color: var(--text-dim); letter-spacing: 0.8px; white-space: nowrap; min-width: 28px; }
.ctrl-hex { width: 76px !important; font-size: 10px !important; }
.ctrl-num { width: 50px !important; padding: 5px 5px !important; }
.ctrl-stack { margin-bottom: 8px; }
.ctrl-stack .ctrl-label { display: block; margin-bottom: 3px; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-val { font-size: 9px; color: var(--text-dim); min-width: 30px; text-align: right; }

input[type="text"], input[type="number"], select {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text-bright); font-family: var(--font-mono);
  font-size: 11px; padding: 6px 7px; border-radius: 2px; width: 100%;
  transition: border-color var(--tr); -webkit-appearance: none;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 1px rgba(0,255,136,0.08);
}
input[type="color"] {
  width: 32px; height: 26px; padding: 2px; border-radius: 2px;
  border: 1px solid var(--border); background: var(--bg2); cursor: pointer; flex-shrink: 0;
}
input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 3px;
  background: var(--border2); border-radius: 2px; cursor: pointer; flex: 1;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 10px; height: 10px;
  border-radius: 50%; background: var(--green);
  box-shadow: 0 0 5px rgba(0,255,136,0.4);
}
select option { background: var(--bg2); }

.highlight-presets { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.hl-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.08); cursor: pointer;
  transition: transform var(--tr), box-shadow var(--tr);
}
.hl-dot:hover { transform: scale(1.25); box-shadow: 0 0 6px currentColor; }

/* ── Right Sidebar ── */
.field-stack { margin-bottom: 7px; }
.field-label { display: block; font-size: 8px; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 3px; }
.field-input { font-size: 10px !important; padding: 5px 7px !important; }

.logo-preview-wrap {
  width: 100%; min-height: 50px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 2px;
  display: flex; align-items: center; justify-content: center; padding: 8px;
}
.logo-placeholder { font-size: 9px; color: var(--text-muted); letter-spacing: 2px; }

.sb-btn {
  padding: 5px 8px; background: var(--bg2); border: 1px solid var(--border);
  color: var(--text-mid); font-family: var(--font-mono);
  font-size: 9px; letter-spacing: 1px; cursor: pointer; border-radius: 2px;
  transition: all var(--tr); text-transform: uppercase; white-space: nowrap;
}
.sb-btn:hover   { border-color: var(--border2); color: var(--text-bright); }
.sb-btn.full    { width: 100%; }
.sb-btn.accent  { border-color: var(--green-dim); color: var(--green-dim); }
.sb-btn.accent:hover { border-color: var(--green); color: var(--green); background: rgba(0,255,136,0.04); }
.sb-btn.danger  { color: var(--red-dim); border-color: var(--red-dim); }
.sb-btn.danger:hover { color: var(--red); border-color: var(--red); background: rgba(255,68,68,0.04); }

.attachment-list { min-height: 36px; margin-bottom: 7px; }
.no-attachments { font-size: 9px; color: var(--text-muted); letter-spacing: 1px; padding: 10px 0; text-align: center; }
.attachment-item { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 9px; }
.attach-info { display: flex; flex-direction: column; gap: 1px; }
.attach-name { color: var(--text-mid); }
.attach-meta { color: var(--text-dim); font-size: 8px; }
.attach-del { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 10px; padding: 2px; transition: color var(--tr); }
.attach-del:hover { color: var(--red); }

.flag-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.flag-item { display: flex; align-items: center; gap: 5px; font-size: 9px; letter-spacing: 0.5px; color: var(--text-dim); cursor: pointer; padding: 2px 0; transition: color var(--tr); }
.flag-item:hover { color: var(--text-mid); }
.flag-item input[type="checkbox"] { width: 12px; height: 12px; padding: 0; accent-color: var(--green); cursor: pointer; flex-shrink: 0; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat-item { text-align: center; padding: 7px; background: var(--bg2); border: 1px solid var(--border); border-radius: 2px; }
.stat-val { font-size: 20px; color: var(--green); font-family: var(--font-display); line-height: 1; }
.stat-key { font-size: 7px; color: var(--text-dim); letter-spacing: 1px; margin-top: 2px; }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.shortcut-list { display: flex; flex-direction: column; gap: 5px; }
.sc-item { display: flex; justify-content: space-between; align-items: center; }
.sc-key { background: var(--bg2); border: 1px solid var(--border2); border-radius: 2px; padding: 1px 5px; font-size: 9px; color: var(--text-mid); }
.sc-desc { font-size: 9px; color: var(--text-dim); }

/* ════ CANVAS AREA ════ */
.canvas-area {
  display: flex; flex-direction: column; background: var(--bg); overflow: hidden;
}

/* Toolbar */
.canvas-toolbar {
  height: var(--toolbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 10px; gap: 6px;
  flex-shrink: 0; overflow-x: auto; overflow-y: hidden;
}
.toolbar-group { display: flex; gap: 2px; }
.tb-btn {
  padding: 4px 8px; background: none; border: 1px solid transparent;
  color: var(--text-dim); font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.5px; cursor: pointer; border-radius: 2px;
  transition: all var(--tr); white-space: nowrap;
}
.tb-btn:hover { border-color: var(--border2); color: var(--text-bright); background: var(--surface2); }
.toolbar-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }

.zoom-widget { display: flex; align-items: center; gap: 4px; background: var(--bg2); border: 1px solid var(--border); border-radius: 2px; padding: 2px 7px; margin-left: auto; flex-shrink: 0; }
.zoom-btn { background: none; border: none; color: var(--text-mid); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; transition: color var(--tr); }
.zoom-btn:hover { color: var(--green); }
#zoomLabel { font-size: 10px; color: var(--text-mid); min-width: 36px; text-align: center; }
.zoom-range { width: 70px; flex-shrink: 0; border: none !important; background: none !important; box-shadow: none !important; padding: 0 !important; }

/* Viewport */
.canvas-viewport {
  flex: 1; overflow: auto;
  display: flex; justify-content: center;
  padding: 28px 18px calc(28px + var(--statusbar-h));
  background:
    radial-gradient(ellipse at center, #141414 0%, #0a0a0a 100%);
  position: relative;
}

/* Ruler overlay */
.ruler-overlay {
  position: absolute; top: 0; left: 0; right: 0;
  height: 22px; background: #1a1a1a; border-bottom: 1px solid var(--border);
  pointer-events: none; z-index: 50;
  background-image: repeating-linear-gradient(90deg, var(--border) 0px, var(--border) 1px, transparent 1px, transparent 20px);
}

/* ════ EMAIL CANVAS ════ */
.email-canvas {
  background: #ffffff; border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2), 0 8px 60px rgba(0,0,0,0.7);
  transform-origin: top center; transition: box-shadow 0.3s;
  width: 820px; min-height: 600px;
  position: relative; overflow: hidden;
}

/* Priority + classification stripes at top of canvas */
.priority-stripe {
  width: 100%; height: 0;
  transition: height 0.2s, background 0.2s;
  position: relative; z-index: 3;
}
.class-stripe {
  width: 100%; height: 0;
  transition: height 0.2s, background 0.2s;
  position: relative; z-index: 3;
}

/* Canvas noise layer */
.canvas-noise-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
  opacity: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  transition: opacity 0.3s;
  mix-blend-mode: multiply;
}

/* ═══ NEW: Canvas texture layer ═══ */
.canvas-texture-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  opacity: 0;
  transition: opacity 0.3s;
  mix-blend-mode: multiply;
  background-size: cover;
}

/* Coffee stain texture */
.canvas-texture-layer.texture-coffee {
  background:
    radial-gradient(ellipse 80px 70px at 75% 25%, rgba(139,90,43,0.35) 0%, rgba(139,90,43,0.15) 40%, transparent 70%),
    radial-gradient(ellipse 50px 55px at 20% 70%, rgba(120,75,30,0.25) 0%, rgba(120,75,30,0.08) 50%, transparent 75%),
    radial-gradient(circle 30px at 85% 80%, rgba(150,100,50,0.2) 0%, rgba(150,100,50,0.05) 60%, transparent 80%),
    radial-gradient(ellipse 20px 25px at 45% 15%, rgba(130,85,35,0.18) 0%, transparent 70%),
    radial-gradient(circle 15px at 60% 55%, rgba(140,95,40,0.12) 0%, transparent 65%);
  background-size: 100% 100%;
}

/* Burn mark texture */
.canvas-texture-layer.texture-burn {
  background:
    radial-gradient(ellipse 120px 90px at 10% 90%, rgba(40,20,5,0.6) 0%, rgba(80,40,10,0.3) 30%, rgba(120,70,20,0.1) 60%, transparent 80%),
    radial-gradient(ellipse 80px 100px at 95% 5%, rgba(50,25,5,0.4) 0%, rgba(90,50,15,0.15) 40%, transparent 70%),
    radial-gradient(ellipse 40px 50px at 50% 95%, rgba(30,15,3,0.35) 0%, rgba(70,35,10,0.1) 50%, transparent 75%);
  background-size: 100% 100%;
}

/* ═══ NEW: Canvas vignette layer ═══ */
.canvas-vignette-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 6;
  opacity: 0; transition: opacity 0.4s;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.25) 100%);
}
.canvas-vignette-layer.active { opacity: 1; }

/* ═══ NEW: Canvas scanline layer ═══ */
.canvas-scanline-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 6;
  opacity: 0; transition: opacity 0.3s;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(0,0,0,0.04) 3px, rgba(0,0,0,0.04) 4px
  );
}
.canvas-scanline-layer.active { opacity: 1; }

/* ═══ NEW: Canvas fold lines layer ═══ */
.canvas-fold-layer {
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
  opacity: 0; transition: opacity 0.3s;
}
.canvas-fold-layer.active { opacity: 1; }
.canvas-fold-layer::before {
  content: '';
  position: absolute; top: 33.3%; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent 5%, rgba(0,0,0,0.08) 20%, rgba(0,0,0,0.12) 50%, rgba(0,0,0,0.08) 80%, transparent 95%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.canvas-fold-layer::after {
  content: '';
  position: absolute; top: 66.6%; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent 5%, rgba(0,0,0,0.08) 20%, rgba(0,0,0,0.12) 50%, rgba(0,0,0,0.08) 80%, transparent 95%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.canvas-inner {
  padding: 55px 70px;
  position: relative; z-index: 5;
}

.email-header-band { position: absolute; top: 0; left: 0; right: 0; height: 0; z-index: 1; }

/* ── Email Meta ── */
.email-meta-block { margin-bottom: 0; }

.meta-logo-row { display: flex; align-items: flex-start; gap: 18px; margin-bottom: 14px; }
.meta-logo {
  object-fit: contain; border: 1px solid #ddd; border-radius: 2px;
  flex-shrink: 0; cursor: pointer; transition: border-color 0.2s;
  display: block;
}
.meta-logo:hover { border-color: #999; }

.meta-fields-col { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.meta-seed   { font-size: 11px; font-weight: 700; letter-spacing: 0.5px; }
.meta-from   { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.meta-status { font-size: 17px; font-weight: 600; }
.meta-rows   { display: flex; flex-direction: column; gap: 2px; margin-top: 7px; }
.meta-row    { font-size: 12px; font-weight: 500; display: flex; gap: 6px; align-items: baseline; }
.meta-row-key { font-size: 9px; letter-spacing: 2px; opacity: 0.5; min-width: 42px; }

.classification-banner {
  text-align: center; font-size: 11px; letter-spacing: 4px;
  font-weight: 700; padding: 5px; margin-bottom: 14px; text-transform: uppercase;
}
.flags-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.flag-badge { font-size: 8px; letter-spacing: 1.5px; border: 1px solid; padding: 2px 5px; border-radius: 1px; text-transform: uppercase; }
.priority-badge { font-size: 9px; font-weight: bold; letter-spacing: 2px; padding: 3px 10px; border: 2px solid; text-transform: uppercase; display: inline-block; margin-bottom: 8px; }

.email-divider-rule { border: none; height: 1px; background: #ccc; margin: 20px 0; }

.email-body {
  font-size: 17px; line-height: 1.7; letter-spacing: -0.1px;
  outline: none; min-height: 120px; position: relative;
}
.email-body[contenteditable="true"]:hover { background: rgba(0,0,255,0.02); border-radius: 2px; }
.email-body[contenteditable="true"]:focus { background: rgba(0,0,255,0.03); border-radius: 2px; }

/* Inline elements in body — FIXED: use CSS var for dynamic color */
.redacted-span {
  background: #111 !important; color: #111 !important;
  padding: 0 4px; border-radius: 1px; cursor: default;
  display: inline; user-select: none;
}
.highlight-mark {
  border-bottom: 2px solid var(--hl-color, #f6c050);
  padding-bottom: 1px;
}
.highlight-bg { padding: 0 2px; border-radius: 1px; background: rgba(246,192,80,0.27); }
.highlight-box { border: 1.5px solid var(--hl-color, #f6c050); padding: 0 2px; border-radius: 1px; }
.highlight-dbl { border-bottom: 3px double var(--hl-color, #f6c050); padding-bottom: 1px; }

.glitch-span {
  position: relative; display: inline-block;
  animation: glitchTextInline 5s infinite;
}

.email-footer-block {
  margin-top: 40px; font-size: 12px; font-weight: 700; outline: none;
}
.email-footer-block[contenteditable="true"]:hover { background: rgba(0,0,255,0.02); border-radius: 2px; }
.email-footer-block[contenteditable="true"]:focus { background: rgba(0,0,255,0.03); border-radius: 2px; }

/* ════ ARC MEMOIR TEMPLATE ════ */
.tpl-arc-memoir { background: #fff; font-family: 'Red Hat Display', sans-serif; }
.arc-letterhead-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px;
}
.arc-logo-col { display: flex; align-items: flex-start; gap: 14px; }
.arc-dept-col { display: flex; flex-direction: column; gap: 2px; }
.arc-dept-location { font-size: 14px; font-weight: 700; color: #111; letter-spacing: 0.5px; }
.arc-dept-entity   { font-size: 14px; font-weight: 700; color: #111; }
.arc-dept-district { font-size: 14px; font-weight: 700; color: #111; text-decoration: underline; }
.arc-date-col {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  font-size: 14px; font-weight: 700;
}
.arc-rec-row { font-size: 14px; }
.arc-rec-bold { font-weight: 900; }
.arc-barcode {
  font-family: 'Libre Barcode 128', 'Courier New', monospace;
  font-size: 32px; letter-spacing: -1px; color: #000;
  margin: 10px 0 16px;
  line-height: 1;
}
.arc-barcode-sim {
  display: flex; align-items: center; height: 28px; gap: 1px; margin: 10px 0 16px;
  overflow: hidden; width: 260px;
}
.arc-barcode-sim span {
  display: inline-block; height: 100%; background: #000; flex-shrink: 0;
}
.arc-form-section { margin-bottom: 14px; }
.arc-section-title { font-size: 14px; font-weight: 900; text-decoration: underline; margin-bottom: 6px; color: #111; }
.arc-field-row { font-size: 13px; color: #111; margin-bottom: 3px; font-weight: 400; }
.arc-field-bold { font-weight: 700; }
.arc-for-row { font-size: 14px; font-weight: 700; color: #111; margin-bottom: 4px; }
.arc-subj-row { font-size: 13px; color: #111; margin-top: 10px; }
.arc-subj-label { font-weight: 700; }

/* ════ BOS MEMOIR TEMPLATE ════ */
.tpl-bos-memoir { background: #fff; }
.bos-top-section { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.bos-left-col { display: flex; flex-direction: column; gap: 3px; }
.bos-area { font-size: 15px; font-weight: 700; color: #111; }
.bos-archive { font-size: 15px; font-weight: 700; color: #111; }
.bos-from { font-size: 15px; font-weight: 700; color: #111; text-decoration: underline; }
.bos-classified { font-size: 14px; color: #111; text-decoration: underline; margin-top: 2px; }
.bos-right-col { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.bos-date-row { font-size: 13px; font-weight: 700; text-align: right; color: #111; }
.bos-rec-row  { font-size: 13px; font-weight: 700; text-align: right; color: #111; }

/* BOS Image (replaces globe) */
.bos-image-frame {
  margin-top: 8px;
  border: 1.5px solid #000;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: border-color 0.2s;
}
.bos-image-frame:hover { border-color: #666; }
.bos-image-placeholder {
  display: flex; align-items: center; justify-content: center;
  background: #f5f5f5;
  text-align: center;
}

.bos-to-row { font-size: 14px; color: #111; margin-bottom: 4px; }
.bos-to-label { font-weight: 700; }
.bos-re-row { font-size: 14px; color: #111; margin-bottom: 16px; }
.bos-re-label { font-weight: 700; }
.bos-body-text { font-size: 14px; line-height: 1.65; color: #111; text-align: left; }
.bos-indent { text-indent: 40px; margin-bottom: 14px; }
.bos-signature { text-align: right; font-size: 14px; color: #111; text-decoration: underline; margin-top: 30px; }

/* ════ TEMPLATE OVERRIDES ════ */
.tpl-signal .email-body, .tpl-signal .email-footer-block { color: #aaffaa; }
.tpl-signal .email-meta-block { color: #88cc88; }
.tpl-signal .meta-from { color: #00ff88; }
.tpl-signal .email-divider-rule { background: #1a3a1a; }

.tpl-classified .email-body { font-family: 'Times New Roman', serif; color: #1a1a1a; }
.tpl-classified .classification-banner { color: #cc0000; border-top: 2px solid #cc0000; border-bottom: 2px solid #cc0000; }
.tpl-classified .email-divider-rule { background: #cc0000; height: 2px; }

.tpl-ghost .email-body { color: #666; font-style: italic; }
.tpl-ghost .meta-from  { color: #bbb; }
.tpl-ghost .email-divider-rule { background: #e0e0e0; }

.tpl-transmission .email-body, .tpl-transmission .email-footer-block { color: #aaeeff; font-family: 'IBM Plex Mono', monospace; }
.tpl-transmission .meta-from { color: #00eeff; }
.tpl-transmission .email-divider-rule { background: repeating-linear-gradient(90deg, #0af 0, #0af 4px, transparent 4px, transparent 8px); height: 2px; background-color: transparent; }

.tpl-corporate .meta-from { color: #111; font-family: Georgia, serif; }
.tpl-corporate .email-body { font-family: Georgia, serif; color: #222; font-size: 16px; }

/* ════ STATUSBAR ════ */
.statusbar {
  height: var(--statusbar-h);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 12px; gap: 8px;
  flex-shrink: 0; font-size: 9px; color: var(--text-dim);
  letter-spacing: 0.8px; overflow: hidden;
  position: fixed; bottom: 0; left: var(--sidebar-w); right: var(--sidebar-r);
  z-index: 100;
}
.sb-sep { color: var(--border2); }
.saved-indicator { color: var(--green-dim); margin-left: auto; }
.saved-indicator.dirty { color: var(--amber-dim); }

/* ════ NOTIFICATIONS ════ */
.notif-container { position: fixed; top: 54px; right: 14px; z-index: 1000; display: flex; flex-direction: column; gap: 6px; }
.notif {
  background: var(--surface); border: 1px solid var(--green);
  color: var(--green); padding: 9px 14px; border-radius: 2px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.8px;
  animation: notifIn 0.22s ease-out forwards;
  box-shadow: 0 4px 20px rgba(0,255,136,0.08);
  max-width: 270px;
}
.notif.warn  { border-color: var(--amber); color: var(--amber); box-shadow: 0 4px 20px rgba(246,192,80,0.08); }
.notif.error { border-color: var(--red);   color: var(--red);   box-shadow: 0 4px 20px rgba(255,68,68,0.08); }
.notif.fade-out { animation: notifOut 0.28s ease-in forwards; }

/* ════ FIND & REPLACE ════ */
.find-replace-panel {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border2);
  padding: 14px; border-radius: 3px; z-index: 500;
  min-width: 300px; box-shadow: 0 8px 30px rgba(0,0,0,0.7);
}
.fr-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.fr-label { font-size: 9px; letter-spacing: 1px; color: var(--text-dim); min-width: 52px; }
.fr-input { flex: 1; font-size: 11px !important; padding: 5px 8px !important; }
.fr-btns { display: flex; gap: 5px; }
.fr-count { font-size: 9px; color: var(--text-dim); margin-top: 6px; letter-spacing: 1px; }

/* ════ MODAL ════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border2);
  padding: 22px 26px; width: 300px; border-radius: 4px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.modal-title { font-size: 11px; letter-spacing: 2px; color: var(--green-dim); border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.modal-input { margin-bottom: 0; }
.modal-btns { display: flex; gap: 7px; }

/* ════ ANIMATIONS ════ */
@keyframes scanRoll { 0% { background-position: 0 0; } 100% { background-position: 0 400px; } }
@keyframes blinkSlow { 0%, 49%, 100% { opacity:1; } 50%, 99% { opacity:0; } }
@keyframes urgentBlink { 0%, 100% { opacity:1; } 50% { opacity:0.2; } }
@keyframes notifIn  { from { transform: translateX(300px); opacity:0; } to   { transform: translateX(0);     opacity:1; } }
@keyframes notifOut { from { transform: translateX(0);     opacity:1; } to   { transform: translateX(300px); opacity:0; } }

@keyframes glitchTextInline {
  0%, 90%, 100% { clip-path: none; transform: none; filter: none; }
  91% { clip-path: inset(25% 0 55% 0); transform: translateX(-4px); filter: hue-rotate(90deg); }
  92% { clip-path: inset(65% 0 10% 0); transform: translateX(4px); }
  93% { clip-path: none; }
}

@keyframes canvasGlitchAnim {
  0%, 92%, 100% { }
  93% { filter: hue-rotate(3deg); }
  94% { transform: translateX(3px); }
  95% { transform: translateX(-3px); filter: saturate(1.5); }
  96% { transform: none; }
}

body.glitch-mode .email-canvas {
  animation: canvasGlitchAnim 5s infinite;
}

/* ════ RESPONSIVE ════ */
@media (max-width: 1100px) {
  :root { --sidebar-w: 0px; --sidebar-r: 0px; }
  .sidebar-left, .sidebar-right { display: none; }
  .statusbar { left: 0; right: 0; }
}
