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

:root {
    --bg:        #0a0f1e;
    --bg2:       #0d1529;
    --bg3:       #111d38;
    --border:    #1e3060;
    --accent:    #1428A0;
    --blue:      #4a90d9;
    --blue-lt:   #7ab3e8;
    --text:      #dde6f5;
    --text-dim:  #6a85b0;
    --success:   #00c49f;
    --warn:      #f5a623;
    --card-r:    10px;
}

html, body { height: 100%; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
}

/* ── HEADER ── */
.app-header {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-size: 15px; font-weight: 600; color: var(--text); }
.brand-sub   { font-size: 11px; color: var(--text-dim); }
.header-actions { display: flex; align-items: center; gap: 12px; }
.loaded-file { font-size: 12px; color: var(--text-dim); }
.btn-ghost {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: color .2s, border-color .2s;
}
.btn-ghost:hover { color: var(--blue); border-color: var(--blue); }

/* ── MAIN ── */
.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

/* ── UPLOAD SCREEN ── */
#upload-screen { display: flex; flex-direction: column; align-items: center; padding-top: 80px; }

.upload-zone {
    width: 100%;
    max-width: 560px;
    border: 2px dashed var(--border);
    border-radius: var(--card-r);
    padding: 56px 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    background: var(--bg2);
    position: relative;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--blue);
    background: var(--bg3);
}
.upload-zone input[type="file"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.upload-icon { margin-bottom: 20px; }
.upload-zone h2 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.upload-hint  { font-size: 14px; color: var(--text-dim); margin-bottom: 6px; }
.link-text    { color: var(--blue); text-decoration: underline; }
.upload-sub   { font-size: 12px; color: var(--text-dim); opacity: .7; max-width: 360px; margin: 0 auto; }

.error-banner {
    margin-top: 20px;
    max-width: 560px;
    width: 100%;
    background: rgba(220,50,50,.12);
    border: 1px solid rgba(220,50,50,.4);
    border-radius: 8px;
    padding: 12px 16px;
    color: #f08080;
    font-size: 13px;
}

/* ── PROJECT CARD ── */
.project-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--card-r);
    padding: 20px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.info-item { display: flex; flex-direction: column; gap: 3px; }
.info-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.info-value { font-size: 14px; font-weight: 500; color: var(--text); }
.info-value.highlight { color: var(--blue-lt); font-size: 16px; font-weight: 700; }
.tag {
    display: inline-block;
    background: rgba(74,144,217,.15);
    border: 1px solid rgba(74,144,217,.3);
    color: var(--blue-lt);
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
}

/* ── CONTROLS BAR ── */
.controls-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.tab-group, .voltage-group { display: flex; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }

.tab, .vtab {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 8px 18px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.tab.active, .vtab.active {
    background: var(--accent);
    color: #fff;
}
.tab:not(.active):hover, .vtab:not(.active):hover { background: var(--bg); color: var(--text); }

.export-group { margin-left: auto; display: flex; gap: 8px; }
.btn-export {
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity .2s;
}
.btn-export:hover { opacity: .85; }

/* ── DIAGRAM AREA ── */
.diagram-wrap {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--card-r);
    min-height: 480px;
    max-height: 80vh;
    position: relative;
    overflow: auto;
    padding: 24px;
}
#diagram-output {
    display: flex;
    justify-content: center;
}
#diagram-output svg {
    max-width: 100%;
    height: auto;
}

.diagram-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-dim);
    font-size: 14px;
    background: var(--bg2);
}
.spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LEGEND ── */
.legend {
    margin-top: 12px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.legend-dot  { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ── DEBUG PANEL ── */
.debug-panel {
    margin-top: 12px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--card-r);
    font-size: 12px;
}
.debug-panel summary {
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-dim);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 12px;
}
.debug-panel summary:hover { color: var(--text); }
.btn-copy-text {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 3px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    transition: color .2s, border-color .2s;
}
.btn-copy-text:hover { color: var(--blue); border-color: var(--blue); }
#debug-table {
    padding: 0 16px 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 4px 16px;
}
.debug-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.debug-section { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); opacity: .5; padding-top: 8px; border-bottom: none; }
.debug-key  { color: var(--text-dim); }
.debug-val  { color: var(--blue-lt); font-weight: 500; }
.debug-val.missing { color: #f08080; }

/* ── UTILITIES ── */
.hidden { display: none !important; }

/* ── FOCUS (keyboard nav) ── */
.tab:focus-visible,
.vtab:focus-visible,
.btn-ghost:focus-visible,
.btn-export:focus-visible,
.btn-copy-text:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}


/* ── GOOGLE VISION REPORT ── */
.gv-wrap { padding: 4px 0; }

.gv-pending, .gv-error {
    padding: 16px 20px;
    border-radius: var(--card-r);
    font-size: 14px;
}
.gv-pending { background: var(--bg2); color: var(--text-dim); }
.gv-error   { background: rgba(200,50,50,.15); color: #f08080; border: 1px solid rgba(200,50,50,.3); }

.gv-report { display: flex; flex-direction: column; gap: 16px; }

.gv-section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--card-r);
    padding: 14px 16px;
}

.gv-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--blue-lt);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: default;
}
details.gv-section > summary.gv-section-title { cursor: pointer; list-style: none; }
details.gv-section > summary.gv-section-title::before { content: '▶ '; font-size: 10px; color: var(--text-dim); }
details.gv-section[open] > summary.gv-section-title::before { content: '▼ '; }

.gv-count {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-dim);
    text-transform: none;
    letter-spacing: 0;
}

.gv-text-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg3);
    border-radius: 6px;
    padding: 10px 12px;
}
.gv-text-line {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
}

.gv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.gv-table th, .gv-table td {
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
}
.gv-table th  { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.gv-table td  { color: var(--text); }
.gv-table tr:last-child td { border-bottom: none; }

.gv-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.gv-tag {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 12px;
    color: var(--text);
}
.gv-tag em { color: var(--text-dim); font-style: normal; }

.gv-json {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-dim);
    white-space: pre;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg3);
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 8px;
}
