:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #26334d;
    --surface-3: #334155;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --border: #475569;
    --radius: 12px;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.5;
    min-height: 100vh;
}

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 2rem;
    text-decoration: none;
    color: var(--text);
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: grid;
    place-items: center;
}

.brand-icon svg {
    width: 22px;
    height: 22px;
    fill: white;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-links a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-links a.active {
    background: var(--surface-2);
    color: var(--text);
}

.nav-links a svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 2rem;
    max-width: calc(100vw - 240px);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.editor-grid {
    display: grid;
    grid-template-columns: 1fr 320px 320px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1200px) {
    .editor-grid {
        grid-template-columns: 1fr 1fr;
    }
    .panel-preview {
        order: -1;
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .sidebar { width: 100%; position: relative; height: auto; }
    .main-content { margin-left: 0; max-width: 100%; padding: 1rem; }
    .app-layout { flex-direction: column; }
    .editor-grid { grid-template-columns: 1fr; }
}

.panel h3 {
    margin: 0 0 1rem;
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.type-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.type-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s;
}

.type-tab:hover {
    background: var(--surface-3);
    color: var(--text);
}

.type-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.type-tab svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.type-fields {
    display: none;
}

.type-fields.active {
    display: block;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}

.form-control:focus {
    border-color: var(--primary);
}

input[type="color"].form-control {
    width: 42px;
    height: 42px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

textarea.form-control {
    min-height: 90px;
    resize: vertical;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox input {
    width: 18px;
    height: 18px;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-row input[type="text"] {
    flex: 1;
}

.preview-box {
    background: #fff;
    border-radius: var(--radius);
    min-height: 280px;
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
}

.preview-box img {
    max-width: 100%;
    max-height: 300px;
    object-fit: contain;
}

.preview-placeholder {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:hover {
    background: var(--surface-3);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

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

.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--text-muted);
}

.alert {
    padding: 0.9rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.alert.success {
    background: rgba(34, 197, 94, 0.15);
    border-color: var(--success);
    color: var(--success);
}

.login-box {
    max-width: 360px;
    margin: 4rem auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.qr-thumb img {
    width: 50px;
    height: 50px;
    object-fit: contain;
    border-radius: 6px;
}

.help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.hidden { display: none !important; }
