/* ============================================================
   UK Debt Clock — vanilla CSS for the PHP version.
   ============================================================ */

:root {
    --bg: #0a0a0a;
    --surface: #121212;
    --surface-2: #0f0f0f;
    --surface-hover: #1a1a1a;
    --border: #2a2a2a;
    --text: #ffffff;
    --text-muted: #8a8a8e;
    --text-dim: #52525b;
    --red: #FF3B30;
    --green: #00C853;
    --blue: #3B9EFF;
    --orange: #FF9500;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
    font-family: 'Manrope', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased; }
body { min-height: 100vh;
    background-image: radial-gradient(circle at 20% 10%, rgba(0,122,255,0.05) 0%, transparent 50%),
                      radial-gradient(circle at 90% 80%, rgba(255,59,48,0.04) 0%, transparent 55%),
                      linear-gradient(180deg, #0a0a0a 0%, #050505 100%);
    background-attachment: fixed; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.uppercase { text-transform: uppercase; letter-spacing: 0.18em; }
.small { font-size: 11px; }
.bold { font-weight: 700; }
.text-white { color: var(--text); }
.text-muted { color: var(--text-muted); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-blue { color: var(--blue); }
.bg-red { background: var(--red); } .bg-green { background: var(--green); }
.bg-orange { background: var(--orange); } .bg-blue { background: var(--blue); }
.right { text-align: right; }

.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(.85); } }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes flash { 0% { text-shadow: 0 0 0 transparent; } 30% { text-shadow: 0 0 18px currentColor; } 100% { text-shadow: 0 0 0 transparent; } }
.flash { animation: flash .9s ease-out; }

/* Grain overlay */
.uk-grain::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.08 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    opacity: 0.35; mix-blend-mode: overlay; }

/* HEADER */
.site-header { position: sticky; top: 0; z-index: 30; background: rgba(10,10,10,.95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.header-inner { max-width: 1920px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-square { width: 38px; height: 38px; background: var(--red); color: #fff; font-weight: 900; font-size: 18px; display: flex; align-items: center; justify-content: center; }
.brand h1 { font-size: 20px; font-weight: 900; margin: 0; line-height: 1.1; }
.brand-eyebrow { font-size: 10px; color: var(--text-dim); line-height: 1; margin-bottom: 2px; }
.header-clock { color: var(--text-muted); font-size: 12px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.currency-toggle { display: inline-flex; border: 1px solid var(--border); background: var(--surface-2); }
.currency-toggle .cur { background: transparent; color: var(--text-muted); border: 0; padding: 6px 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; transition: background .15s, color .15s; font-family: 'JetBrains Mono', monospace; }
.currency-toggle .cur:hover { background: var(--surface-hover); color: var(--text); }
.currency-toggle .cur.active { background: var(--text); color: #000; }
.fx-rates { color: var(--text-dim); font-size: 10px; }
.status-live { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid rgba(0,200,83,0.4); background: rgba(0,200,83,0.1); color: var(--green); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; }
.last-sync { color: var(--text-dim); font-size: 10px; }

/* TICKER */
.ticker-wrap { width: 100%; overflow: hidden; border-top: 1px solid #1a1a1a; border-bottom: 1px solid #1a1a1a; background: #0d0d0d; padding: 8px 0; }
.ticker-track { display: flex; white-space: nowrap; width: 200%; }
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.marquee { animation: marquee 80s linear infinite; }
.ticker-row { display: flex; }
.ticker-item { display: inline-flex; align-items: center; gap: 12px; padding: 0 24px; border-right: 1px solid #1a1a1a; }
.ticker-label { color: var(--text-dim); font-size: 10px; }
.ticker-value { font-size: 14px; }

/* MAIN */
.container { max-width: 1920px; margin: 0 auto; padding: 16px; position: relative; z-index: 2; }

/* TOOLBAR */
.toolbar { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); margin-bottom: 16px; }
.tool-btn { background: var(--surface-2); border: 0; padding: 14px 16px; text-align: left; transition: background .15s; color: var(--text); }
.tool-btn:hover { background: var(--surface-hover); }
.tool-head { display: flex; align-items: center; justify-content: space-between; }
.tool-label { font-size: 10px; font-weight: 700; }
.tool-arrow { color: var(--text-dim); font-size: 18px; transition: color .15s; }
.tool-btn:hover .tool-arrow { color: var(--text); }
.tool-sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* HERO */
.hero-row { display: grid; grid-template-columns: 1fr 360px; gap: 16px; margin-bottom: 1px; }
@media (max-width: 1280px) { .hero-row { grid-template-columns: 1fr; } }
.hero { border: 1px solid var(--border); background: var(--surface-2); padding: 40px; cursor: pointer; outline: none; }
.hero:focus-visible { outline: 1px solid rgba(59,158,255,0.4); }
.hero-label { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3em; color: var(--text-muted); font-weight: 600; }
.hero-value { font-size: clamp(40px, 7vw, 96px); line-height: 1; font-weight: 900; letter-spacing: -0.03em; filter: drop-shadow(0 0 30px rgba(255,59,48,0.2)); margin: 4px 0; }
.hero-sub { font-size: 13px; color: var(--text-muted); margin-top: 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); margin-top: 32px; border: 1px solid var(--border); }
@media (max-width: 960px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } .hero { padding: 24px; } }

/* CELL */
.cell { background: var(--surface); padding: 18px; min-height: 120px; display: flex; flex-direction: column; justify-content: space-between; transition: background .15s; cursor: pointer; outline: none; }
.cell:hover { background: var(--surface-hover); }
.cell:focus-visible { outline: 1px solid rgba(59,158,255,0.4); }
.cell-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.cell-label-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cell-label { color: var(--text-muted); font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { display: block; flex-shrink: 0; }
.cell-value { font-size: 26px; line-height: 1; margin: 12px 0; }
.cell-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text-dim); font-size: 10px; }
.cell-source { color: var(--text-dim); max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* GRIDS */
.grid { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); margin-top: 0; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid.thin { gap: 1px; }
@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } .toolbar { grid-template-columns: 1fr; } }

/* SECTION HEAD */
.section-head { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin: 48px 0 16px; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 22px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; margin: 0; }
.section-head .sub { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.25em; }
.section-head .count { color: var(--text-dim); font-size: 11px; margin-left: auto; }

/* NEWS */
.news-panel { border: 1px solid var(--border); background: var(--surface-2); display: flex; flex-direction: column; }
.news-head { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.news-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.news-eyebrow { color: var(--text-dim); margin-bottom: 4px; }
.news-sync { color: var(--text-dim); }
.news-list { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow-y: auto; }
.news-list .news-empty { padding: 24px 20px; color: var(--text-dim); font-size: 13px; }
.news-list .news-empty code { background: #1a1a1a; padding: 2px 6px; }
.news-item { border-bottom: 1px solid #1a1a1a; padding: 12px 20px; transition: background .15s; }
.news-item:hover { background: #141414; }
.news-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.news-badge { padding: 2px 6px; border: 1px solid; font-size: 9px; font-weight: 700; }
.news-time { color: var(--text-dim); font-size: 10px; }
.news-title { color: #e6e6e6; font-size: 14px; line-height: 1.35; }

/* NATIONS */
.section-block { margin-top: 48px; }
.nation-card { background: var(--surface); padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.nation-head { display: flex; align-items: center; justify-content: space-between; }
.nation-head h3 { margin: 2px 0 0; font-size: 22px; font-weight: 900; letter-spacing: -0.01em; }
.nation-eyebrow { font-weight: 700; font-size: 10px; }
.nation-pop { text-align: right; color: var(--text-dim); font-size: 12px; }
.nation-stat { background: var(--surface-2); padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.nation-stat .uppercase { color: var(--text-dim); font-size: 9px; }
.nation-val { font-size: 13px; font-weight: 600; }

/* G7 */
.g7-bars { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.g7-bars li { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.g7-name { width: 160px; flex-shrink: 0; display: flex; align-items: center; gap: 8px; color: #e6e6e6; }
.g7-name.uk { color: var(--red); font-weight: 700; }
.g7-bar { flex: 1; height: 20px; background: #0a0a0a; border: 1px solid #1f1f1f; position: relative; }
.g7-fill { display: block; height: 100%; background: linear-gradient(90deg, #2a2a2a, #3a3a3a); }
.g7-fill.uk { background: linear-gradient(90deg, #FF3B30, #FF7A6E); }
.g7-val { width: 60px; text-align: right; color: #d4d4d4; font-size: 13px; }
.g7-val.uk { color: var(--red); font-weight: 700; }
.g7-table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 13px; }
.g7-table th { text-align: left; padding: 8px 6px; color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; border-bottom: 1px solid var(--border); font-weight: 600; }
.g7-table td { padding: 8px 6px; border-bottom: 1px solid #1a1a1a; }
.g7-table tr.uk { background: rgba(255,59,48,0.06); }
.g7-table tr.uk td { color: var(--text); }

/* FOOTER */
.page-footer { margin-top: 64px; padding-top: 32px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 13px; }
.page-footer p { margin: 0 0 12px; max-width: 920px; line-height: 1.55; }
.footer-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.footer-sep { color: var(--text-dim); }
.footer-link { color: var(--text-muted); text-decoration: none; transition: color .15s; border-bottom: 1px dotted transparent; }
.footer-link:hover { color: var(--text); border-bottom-color: var(--text-muted); }

/* MODALS */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.85); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { background: var(--bg); border: 1px solid var(--border); width: 100%; max-width: 720px; margin: 32px 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); padding: 12px 20px; }
.modal-head h3 { margin: 0; font-size: 20px; font-weight: 700; }
.modal-close { background: transparent; border: 0; color: var(--text-muted); font-size: 28px; line-height: 1; padding: 0 8px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); align-items: center; }
.btn-primary { background: var(--text); color: #000; border: 0; padding: 8px 16px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; }
.btn-primary:hover { background: #e4e4e4; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 8px 16px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-red { background: var(--red); color: #fff; border: 0; padding: 8px 16px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; }
.btn-red:hover { background: #FF5145; }
.modal-hint { margin-left: auto; color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; }

/* SHARE */
.share-card { position: relative; background: var(--bg); border: 1px solid var(--border); padding: 40px; overflow: hidden; aspect-ratio: 1200/630; }
.share-bg { position: absolute; right: -120px; top: -120px; width: 400px; height: 400px; border-radius: 50%; opacity: 0.1;
    background: radial-gradient(circle, var(--red) 0%, var(--bg) 70%); }
.share-top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; position: relative; }
.share-brand { display: flex; align-items: center; gap: 12px; }
.share-live { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.share-debt-label { color: var(--text-muted); margin-top: 16px; position: relative; }
.share-debt-value { font-size: clamp(28px, 5vw, 56px); line-height: 1; font-weight: 900; letter-spacing: -0.03em; position: relative; }
.share-sub { color: var(--text-muted); font-size: 13px; margin-top: 10px; position: relative; }
.share-kpis { margin-top: 24px; position: relative; }
.share-kpi { background: var(--surface); border: 1px solid #1a1a1a; padding: 10px; }
.share-kpi > div:first-child { color: var(--text-dim); font-size: 9px; }
.share-sources { margin-top: 20px; position: relative; }

/* DRILL */
.drill-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
@media (max-width: 640px) { .drill-stats { grid-template-columns: repeat(2, 1fr); } }
.drill-stat > div:first-child { color: var(--text-dim); font-size: 9px; }
.drill-stat > div:last-child { margin-top: 4px; }
.drill-chart-wrap { padding: 12px 20px; }
#drill-chart { width: 100%; height: 360px; display: block; }
.drill-gov-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 20px 16px; }
@media (max-width: 768px) { .drill-gov-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .drill-gov-grid { grid-template-columns: 1fr; } }
.gov-chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid #1a1a1a; background: var(--surface-2); }
.gov-bar { width: 4px; height: 24px; flex-shrink: 0; }
.gov-chip .gov-name { font-size: 13px; color: var(--text); }
.gov-chip .gov-name span { color: var(--text-dim); font-family: 'JetBrains Mono', monospace; font-size: 10px; margin-left: 4px; }
.gov-chip .gov-chancellor { font-size: 10px; color: var(--text-dim); }

/* THRESHOLDS */
.th-perm { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.th-form { display: grid; grid-template-columns: 5fr 2fr 3fr 2fr; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
@media (max-width: 640px) { .th-form { grid-template-columns: 1fr; } }
.th-form select, .th-form input { background: var(--surface-2); border: 1px solid var(--border); padding: 8px 12px; color: var(--text); font-family: inherit; font-size: 13px; }
.th-form input { font-family: 'JetBrains Mono', monospace; }
.th-form select:focus, .th-form input:focus { outline: none; border-color: var(--blue); }
.th-form .modal-hint { grid-column: 1 / -1; margin: 0; text-align: left; color: var(--text-dim); }
.th-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.th-list .empty { padding: 24px 20px; color: var(--text-dim); font-size: 13px; }
.th-list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid #1a1a1a; }
.th-list .th-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--green); }
.th-list .th-dot.triggered { background: var(--red); animation: pulse 1.6s ease-in-out infinite; }
.th-list .th-info { flex: 1; min-width: 0; }
.th-list .th-info > div:first-child { font-size: 13px; }
.th-list .th-info > div:last-child { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.12em; }
.th-list button { background: transparent; color: var(--text-muted); border: 1px solid var(--border); padding: 4px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; }
.th-list button:hover { color: var(--red); }

/* CHANCELLOR */
.ch-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
@media (max-width: 640px) { .ch-summary { grid-template-columns: repeat(2, 1fr); } }
.ch-sum { background: var(--surface-2); padding: 14px; }
.ch-sum > div:nth-child(2) { font-size: 17px; margin-top: 4px; }
.ch-delta { margin-top: 4px; color: var(--text-dim); }
.ch-delta.up { color: var(--red); }
.ch-delta.down { color: var(--green); }
.ch-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
@media (max-width: 768px) { .ch-cols { grid-template-columns: 1fr; } }
.ch-col { background: var(--surface-2); padding: 20px; }
.ch-col h4 { margin: 0; font-size: 16px; }
.ch-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.ch-list .ch-row-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.ch-list .ch-row-head .ch-val { font-family: 'JetBrains Mono', monospace; color: var(--text); }
.ch-list .ch-row-head .ch-val .ch-pct { color: var(--text-dim); margin-left: 8px; }
.ch-list input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--red); }
