/* cache-bust: v2 */
/* ── Breaking News – App CSS ── */
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,600;1,300&display=swap');

/* ── Variables ── */
:root {
  --ink: #0d0d0d;
  --paper: #f5f0e8;
  --paper-dark: #e8e2d4;
  --red: #b5303a;
  --red-dark: #8a2028;
  --action: #2a5fa5;
  --action-dark: #1e4578;
  --gold: #c9a84c;
  --grey: #6b6560;
  --border: #ccc5b5;
  --sidebar-w: 280px;
  --header-h: 60px;
  --radius: 2px;
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;
  --display: 'Bebas Neue', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}

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

/* ── Layout ── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
  overflow: hidden;
}

.app-shell--no-sidebar {
  grid-template-columns: 1fr;
}

/* ── Header ── */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  background: var(--ink);
  color: #fff;
  border-bottom: 3px solid var(--red);
}

.app-header .logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}

/* Wordmark: "Breaking News" in display font + "Guys" in red italic */
.app-wordmark {
  font-family: var(--display);
  font-size: 1.5rem;
  letter-spacing: 0.1em;
  color: #fff;
  white-space: nowrap;
  line-height: 1;
}

.app-wordmark-guys {
  color: #ce0205;
  font-family: var(--sans);
  font-style: italic;
  font-weight: 300;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  margin-left: 0.35em;
  vertical-align: baseline;
  text-shadow:
    0 0 6px rgba(206, 2, 5, 0.7),
    0 1px 3px rgba(0, 0, 0, 0.9);
}

.header-spacer { flex: 1; }

.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-nav a, .header-nav button {
  color: #ccc;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.3rem 0.6rem;
  transition: color 0.15s;
}
.header-nav a:hover, .header-nav button:hover { color: #fff; text-decoration: none; }

.conn-status-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: #aaa;
}
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #555;
  transition: background 0.3s;
}
.conn-dot.ok { background: #2ecc71; }
.conn-dot.error { background: var(--red); }
.conn-dot.partial { background: var(--gold); }

/* ── Sidebar / History ── */
.app-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper-dark);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
  gap: 0.5rem;
}

.sidebar-header h2 {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--grey);
  flex: 1;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* Frameless icon buttons in the sidebar header */
.sidebar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--grey);
  border-radius: var(--radius);
  padding: 0;
  transition: color 0.1s, background 0.1s;
}
.sidebar-icon-btn:hover {
  color: var(--ink);
  background: var(--paper-dark);
}
.sidebar-icon-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

/* Spinner animation for the refresh button */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.sidebar-icon-btn.spinning span {
  display: inline-block;
  animation: spin 0.7s linear infinite;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 0.5rem;
  /* Thin indicator-only scrollbar -- does not obscure content */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── History row color scale ──
   1. Odd row default:      #f5f0e8  (--paper)
   2. Even row default:     #f0ebe0  (slightly darker)
   3. Hover (non-selected): #e8e3d8
   4. Selected:             #ddd8cc
   5. Hover on selected:    #d5d0c4
   All warm cream tones, each step ~6-7 units darker.
   Text is #0d0d0d -- contrast well above 4.5:1 on all backgrounds.
*/
.history-item {
  border-bottom: 1px solid var(--border);
  position: relative;
  background: #f5f0e8;
}

.history-item:nth-child(even) {
  background: #f0ebe0;
}

/* Selected -- inset box-shadow draws the red bar without shifting content */
.history-item.active {
  background: #ddd8cc;
  box-shadow: inset 3px 0 0 var(--red);
}

.history-row {
  display: flex;
  align-items: stretch;
}

/* Hover on non-selected row */
.history-item:not(.active):hover {
  background: #e8e3d8;
}

/* Hover on selected row */
.history-item.active:hover {
  background: #d5d0c4;
}

.history-row-link {
  flex: 1;
  display: block;
  padding: 0.65rem 0 0.65rem 1rem;
  min-width: 0;
  cursor: pointer;
  text-decoration: none;
}

.history-row-link:hover {
  text-decoration: none;
}

.history-expand-btn {
  flex-shrink: 0;
  width: 2rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--grey);
  font-size: 0.6rem;
  line-height: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.75rem;
  transition: color 0.1s;
}
.history-expand-btn:hover {
  color: var(--ink);
}

/* Collapsed title -- hidden when expanded */
.history-collapsed-title {
  font-weight: 400;
  font-size: 0.88rem;
  line-height: 1.3;
  margin-bottom: 0.15rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Expanded content -- hidden by default, shown via .is-expanded */
.history-expanded-content {
  display: none;
}

.history-item.is-expanded .history-expanded-content {
  display: block;
}

.history-item.is-expanded .history-collapsed-title {
  display: none;
}

.history-expand-headline {
  font-weight: 400;
  font-size: 0.88rem;
  line-height: 1.3;
  margin-bottom: 0.15rem;
  color: var(--ink);
  white-space: normal;
  word-break: break-word;
}

.history-expand-body {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.45rem;
}

.history-expand-image-wrap {
  overflow: hidden;
  max-height: 120px;
}

.history-expand-image {
  display: block;
  max-height: 120px;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: top left;
}

.history-expand-pdf {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--grey);
}

.history-pdf-link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--action);
  text-align: left;
}

.history-pdf-link:hover {
  text-decoration: underline;
}

.history-meta {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--grey);
}

/* Expand All checkbox in sidebar header */
.expand-all-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--grey);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.expand-all-checkbox {
  accent-color: var(--action);
  cursor: pointer;
}
.history-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  background: var(--border);
  color: var(--grey);
  text-transform: uppercase;
  margin-left: 0.3rem;
}
.history-badge.sent { background: #d4edda; color: #155724; }
.history-badge.error { background: #f8d7da; color: #721c24; }

/* ── Main content ── */
.app-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-toolbar {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}

.main-toolbar h1 {
  font-family: var(--display);
  font-size: 1.3rem;
  letter-spacing: 0.06em;
  flex: 1;
}

.msg-view-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
  flex-shrink: 0;
  padding-top: 0.1rem;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ── Message View ── */
.message-card {
  max-width: 760px;
}

.message-headline {
  font-family: var(--display);
  font-size: 2.2rem;
  letter-spacing: 0.04em;
  line-height: 1.15;
  margin-bottom: 0.75rem;
  border-bottom: 3px solid var(--red);
  padding-bottom: 0.5rem;
}

.message-body {
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
  margin-bottom: 1.25rem;
}

.message-image {
  max-width: 100%;
  max-height: 400px;
  object-fit: cover;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
}

/* ── Metrics / Delivery ── */
.delivery-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.delivery-section h3 {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--grey);
  margin-bottom: 0.75rem;
}

.receipt-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.receipt-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 2px solid var(--border);
  color: var(--grey);
  font-weight: 500;
}
.receipt-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.receipt-ok { color: #155724; }
.receipt-fail { color: var(--red-dark); }

/* ── Forms ── */
.form-card {
  max-width: 720px;
}

.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--grey);
  margin-bottom: 0.4rem;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group textarea,
.form-group input[type="file"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 0.95rem;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--red);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  background: var(--paper);
  color: var(--ink);
  transition: all 0.15s;
}
.btn:hover { background: var(--paper-dark); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #333; }
/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.drop-zone.drag-over {
  border-color: var(--action);
  background: rgba(42, 95, 165, 0.06);
}
.drop-hint {
  font-size: 0.78rem;
  color: var(--grey);
  text-align: center;
  padding: 0.5rem 0;
  pointer-events: none;
}
.img-preview {
  display: block;
  max-height: 160px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  object-fit: contain;
}
.pdf-preview-name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.btn-secondary { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.btn-secondary:hover { background: #b08838; text-decoration: none; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: var(--red-dark); color: #fff; text-decoration: none; }
.btn-send { background: var(--action); color: #fff; border-color: var(--action); font-weight: 600; }
.btn-send:hover { background: var(--action-dark); }

/* ── Connection status panel ── */
.conn-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}
.conn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: #e0dbd2;
  background: rgba(255,255,255,0.07);
}
.conn-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #666; }
.conn-chip .dot.ok { background: #2ecc71; }
.conn-chip .dot.error { background: #e74c3c; }
.conn-chip.disabled { opacity: 0.4; }

/* ── Flash messages ── */
.flash-messages { padding: 0.75rem 1.5rem 0; }
.flash {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  border-left: 4px solid transparent;
  transition: opacity 0.4s ease, margin 0.4s ease, padding 0.4s ease;
}
.flash.success { background: #d4edda; border-color: #28a745; color: #155724; }
.flash.error { background: #f8d7da; border-color: var(--red); color: #721c24; }
.flash.warning { background: #fff3cd; border-color: var(--gold); color: #856404; }
.flash.info { background: #d1ecf1; border-color: #17a2b8; color: #0c5460; }
.flash-hidden { opacity: 0; margin: 0; padding-top: 0; padding-bottom: 0; }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  text-align: center;
  color: var(--grey);
  gap: 1rem;
}
.empty-state svg { width: 48px; height: 48px; opacity: 0.3; }
.empty-state h3 { font-family: var(--display); font-size: 1.5rem; letter-spacing: 0.06em; }
.empty-state p { font-size: 0.9rem; max-width: 320px; }

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.login-box {
  background: var(--paper);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  border-top: 5px solid var(--red);
}
.login-logo {
  font-family: var(--display);
  font-size: 2.4rem;
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
}
.login-logo span { color: var(--red); }
.login-tagline { font-family: var(--mono); font-size: 0.7rem; color: var(--grey); margin-bottom: 2rem; text-transform: uppercase; letter-spacing: 0.12em; }
.login-errors { background: #f8d7da; border-left: 4px solid var(--red); padding: 0.6rem 1rem; margin-bottom: 1rem; font-size: 0.85rem; color: #721c24; }

/* ── Inactivity dialog ── */
.inactivity-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.inactivity-overlay.visible { display: flex; }
.inactivity-dialog {
  background: var(--paper);
  padding: 2rem 2.5rem;
  max-width: 380px;
  width: 90%;
  border-top: 5px solid var(--red);
  text-align: center;
}
.inactivity-dialog h2 { font-family: var(--display); font-size: 1.6rem; letter-spacing: 0.06em; margin-bottom: 0.5rem; }
.inactivity-dialog p { font-size: 0.9rem; color: var(--grey); margin-bottom: 1.25rem; }
.countdown {
  font-family: var(--mono);
  font-size: 3rem;
  color: var(--red);
  font-weight: 500;
  margin-bottom: 1.5rem;
}
.inactivity-dialog .btn { margin: 0 0.3rem; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) auto 1fr;
  }
  .app-sidebar { max-height: 220px; }
}

/* ── Password visibility toggle ─────────────────────────────────────────── */
.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap input[type="password"],
.pw-wrap input[type="text"] {
  flex: 1;
  padding-right: 2.4rem !important;
}
.pw-eye {
  position: absolute;
  right: 0.5rem;
  background: none;
  border: none;
  padding: 0.2rem;
  cursor: pointer;
  color: var(--grey);
  display: flex;
  align-items: center;
  line-height: 1;
}
.pw-eye:hover { color: var(--ink); }


/* ── Sidebar drag handle ── */
.sidebar-drag-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}
.sidebar-drag-handle:hover,
.sidebar-drag-handle:active {
  background: var(--action);
  opacity: 0.35;
}
.app-sidebar {
  position: relative;
}

/* ── Account dropdown ── */
.acct-menu {
  position: relative;
}
.acct-trigger {
  color: #ccc;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.3rem 0.6rem;
  transition: color 0.15s;
}
.acct-trigger:hover { color: #fff; }
.acct-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: var(--ink);
  border: 1px solid #444;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 200;
  overflow: hidden;
}
.acct-dropdown.open { display: block; }
.acct-item {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  color: #ccc;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: left;
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}
.acct-item:hover { background: #222; color: #fff; text-decoration: none; }

/* ── History row context menu ── */
.history-context-menu {
  position: absolute;
  top: 0.4rem;
  right: 2.2rem; /* clear of the expand triangle button */
  display: flex;
  align-items: center;
  gap: 0.2rem;
  background: rgba(245, 240, 232, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.3rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  backdrop-filter: blur(2px);
  z-index: 10;
}

/* Show on row hover -- desktop only */
@media (hover: hover) {
  .history-item:hover .history-context-menu {
    opacity: 1;
    pointer-events: auto;
  }
}

.history-context-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  color: var(--grey);
  text-decoration: none;
  transition: color 0.1s, background 0.1s;
}

.history-context-btn:hover {
  color: var(--red);
  background: rgba(181, 48, 58, 0.08);
  text-decoration: none;
}

/* ── New message indicator dot ── */
/* Always occupies space in the nav so surrounding elements never shift.
   Invisible at rest -- lit when new messages arrive. */
.new-msg-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2ecc71;
  flex-shrink: 0;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.new-msg-dot--active {
  opacity: 1;
}

.new-msg-dot--red {
  background: var(--red);
}

@keyframes dot-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); }
  50%  { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

.new-msg-dot--red.new-msg-dot--pulse {
  animation: dot-pulse-red 1.0s ease-out infinite;
}

.new-msg-dot--pulse {
  animation: dot-pulse 1.0s ease-out infinite;
}

@keyframes dot-pulse-red {
  0%   { box-shadow: 0 0 0 0 rgba(181, 48, 58, 0.7); }
  50%  { box-shadow: 0 0 0 6px rgba(181, 48, 58, 0); }
  100% { box-shadow: 0 0 0 0 rgba(181, 48, 58, 0); }
}

/* ── History deleted-item flash ── */
@keyframes history-deleted-flash {
  0%   { background: #f8d7da; }
  60%  { background: #f8d7da; }
  100% { background: inherit; }
}

.history-item--deleted {
  animation: history-deleted-flash 0.75s ease-out forwards;
}

/* ── History new-message highlight ── */
@keyframes history-new-pulse {
  0%   { background: #a8f0c6; }
  60%  { background: #a8f0c6; }
  100% { background: inherit; }
}

.history-item--new {
  animation: history-new-pulse 1.4s ease-out forwards;
}
