:root {
    --ink: #0f172a;
    --ink-soft: #1e293b;
    --paper: #f8fafc;
    --panel: #ffffff;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --blue-soft: #eaf1ff;
    --blue-softer: #f2f7ff;
    --coral: #dc2626;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-soft: #edf1f6;
    --green: #16a34a;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, .08);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .14);
}

* {
    box-sizing: border-box;
}

.editor {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
    width: 100%;
    height: 100vh;
    background: var(--paper);
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
}

header {
    background: var(--ink);
    color: #f1f5f9;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-md);
    z-index: 10;
    flex-shrink: 0;
}

header .brand {
    font-size: 18px;
    font-weight: 600;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.01em;
}

header .brand .mark {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(37, 99, 235, .5);
}

header .brand .sub {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 500;
    color: rgba(241, 245, 249, .5);
    display: block;
    margin-top: -1px;
    letter-spacing: .02em;
}

header .brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.btn {
    font-family: 'Inter', sans-serif;
    font-size: 13.5px;
    font-weight: 600;
    padding: 9px 17px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    transition: transform .08s ease, opacity .15s ease, background .15s ease, box-shadow .15s ease;
}

.btn:active {
    transform: scale(.97);
}

.btn-highlight {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, .35);
}

.btn-highlight:hover {
    background: var(--blue-dark);
}

.btn-ghost {
    background: transparent;
    color: #f1f5f9;
    border-color: rgba(241, 245, 249, .28);
}

.btn-ghost:hover {
    background: rgba(241, 245, 249, .1);
    border-color: rgba(241, 245, 249, .45);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12.5px;
    border-radius: 7px;
}

.btn-outline {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.btn:disabled {
    opacity: .4;
    cursor: not-allowed;
    box-shadow: none;
}

select {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    padding: 8px 11px;
    border-radius: 7px;
    border: 1px solid rgba(241, 245, 249, .28);
    background: rgba(255, 255, 255, .08);
    color: #f1f5f9;
    cursor: pointer;
}

select option {
    color: #111;
}

.workspace {
    flex: 1;
    display: flex;
    min-height: 0;
}

aside {
    height: 100vh;
    background: var(--panel);
    border-right: 1px solid var(--border-soft);
    width: 250px;
    flex-shrink: 0;
    padding: 20px 17px;
    overflow-y: auto;
}

aside.right {
    border-right: none;
    border-left: 1px solid var(--border-soft);
    width: 350px;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.1px;
    color: var(--text-muted);
    margin: 0 0 11px;
}

.stat-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.stat-box {
    background: var(--blue-softer);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 13px;
    flex: 1;
}

.stat-num {
    font-family: 'Fraunces', serif;
    font-size: 25px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
}

.stat-num.accent {
    color: var(--blue);
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.35;
}

.search-box {
    position: relative;
    margin-bottom: 18px;
}

.search-box input {
    width: 100%;
    padding: 9px 12px 9px 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    background: #fff;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-soft);
}

.search-box .icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}

.type-filter {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 6px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 13px;
    transition: background .1s ease;
}

.type-filter:hover {
    background: var(--blue-softer);
}

.type-filter input {
    accent-color: var(--blue);
}

.type-swatch {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    flex-shrink: 0;
}

.type-filter .name {
    flex: 1;
}

.type-filter .count {
    color: var(--text-muted);
    font-size: 12px;
}

.filter-actions {
    display: flex;
    gap: 8px;
    margin: 10px 0 20px;
}

.filter-actions button {
    flex: 1;
    font-size: 11.5px;
    padding: 7px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: #fff;
    cursor: pointer;
    color: var(--text-muted);
    transition: border-color .12s ease, color .12s ease;
}

.filter-actions button:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: var(--paper);
}

#fileInput,
#file {
    display: none;
}

.error-box {
    margin: 60px auto;
    width: min(560px, 90%);
    border: 1px solid #fecaca;
    border-radius: 14px;
    background: #fef2f2;
    padding: 34px 30px;
    text-align: center;
    color: #991b1b;
}

.error-box h3 {
    margin: 0 0 8px;
    font-size: 18px;
}

.error-box p {
    font-size: 13px;
    margin: 0 0 18px;
    color: #b91c1c;
}

.progress-wrap {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    margin: 0 auto 14px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.progress-bar-track {
    width: 220px;
    height: 5px;
    background: var(--border-soft);
    border-radius: 3px;
    margin: 14px auto 0;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--blue);
    width: 0%;
    transition: width .15s ease;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    background: var(--paper);
    text-align: left;
    padding: 11px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    z-index: 1;
}

tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: top;
}

tbody tr {
    cursor: pointer;
    transition: background .1s ease;
}

tbody tr:hover {
    background: var(--blue-softer);
}

tbody tr.active {
    background: var(--blue-soft);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

.content-cell {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-wrap {
    flex: 1;
    overflow: auto;
}

.empty-results {
    padding: 70px 20px;
    text-align: center;
    color: var(--text-muted);
}

.edited-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    margin-right: 6px;
    vertical-align: middle;
}

.color-dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, .15);
    vertical-align: middle;
}

/* right preview panel */
.preview-shell {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: 18px;
}

#previewCanvas {
    display: block;
    width: 100%;
}

.highlight-box {
    position: absolute;
    border: 2px solid var(--coral);
    background: rgba(220, 38, 38, .15);
    border-radius: 2px;
}

.detail-row {
    margin-bottom: 15px;
}

.detail-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.detail-value {
    font-size: 13.5px;
    line-height: 1.55;
}

.detail-value.mono {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.swatch-inline {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 6px;
    border: 1px solid rgba(0, 0, 0, .15);
}

.quoted-text {
    font-style: italic;
    background: var(--blue-softer);
    border-left: 3px solid var(--blue);
    padding: 9px 11px;
    border-radius: 5px;
}

.edit-panel {
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 15px;
    background: var(--panel);
    margin-top: 7px;
    box-shadow: var(--shadow-sm);
}

.edit-panel textarea {
    width: 100%;
    min-height: 72px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    resize: vertical;
    background: #fff;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.edit-panel textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-soft);
}

.edit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 11px;
}

.color-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-input-wrap input[type=color] {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    background: none;
}

.swatch-preset {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, .15);
    cursor: pointer;
    transition: transform .1s ease;
}

.swatch-preset:hover {
    transform: scale(1.1);
}

.swatch-preset.on {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 13px;
}

.edited-pill {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--green);
    background: #dcfce7;
    padding: 2px 9px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.copy-link {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11.5px;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

.copy-link:hover {
    color: var(--blue);
}

#mainArea {
    width: 100%;
}