/* QRRabbit — Minimal CSS for Go-templated UI */

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ========== Theme Variables ========== */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.1);
    --danger: #dc2626;
    --success: #16a34a;
    --info: #2563eb;
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #4f46e5;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --tree-line: #cbd5e1;
    color-scheme: light;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: rgba(129, 140, 248, 0.15);
    --danger: #f87171;
    --success: #4ade80;
    --info: #60a5fa;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --sidebar-bg: #020617;
    --sidebar-text: #94a3b8;
    --sidebar-active: #6366f1;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --tree-line: #475569;
    color-scheme: dark;
}

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

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

/* ========== Auth Pages ========== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-logo {
    height: 48px;
    margin-bottom: 1rem;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

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

.auth-form label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: border-color 0.15s;
    background: var(--surface);
    color: var(--text);
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-footer p + p { margin-top: 0.5rem; }

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

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

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

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

.btn-block { width: 100%; }

.btn-logout {
    display: block;
    padding: 0.5rem;
    color: var(--sidebar-text);
    font-size: 0.8125rem;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius);
    margin-top: 0.5rem;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.05);
    text-decoration: none;
}

/* ========== Alerts ========== */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

[data-theme="dark"] .alert-error {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.2);
}

.alert-info {
    background: #eff6ff;
    color: var(--info);
    border: 1px solid #bfdbfe;
}

[data-theme="dark"] .alert-info {
    background: rgba(96, 165, 250, 0.1);
    border-color: rgba(96, 165, 250, 0.2);
}

.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

[data-theme="dark"] .alert-success {
    background: rgba(74, 222, 128, 0.1);
    border-color: rgba(74, 222, 128, 0.2);
}

/* ========== App Layout ========== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .logo {
    height: 32px;
    filter: brightness(0) invert(1);
}

.sidebar-nav {
    list-style: none;
    padding: 0.5rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: block;
    padding: 0.625rem 1.25rem;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    transition: background 0.15s;
}

.sidebar-nav li a:hover {
    background: rgba(255,255,255,0.05);
    text-decoration: none;
}

.sidebar-nav li.active a {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer .username {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #fff;
    margin-bottom: 0.25rem;
}

.app-main {
    flex: 1;
    margin-left: 240px;
}

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.app-content {
    padding: 1.5rem;
}

/* ========== Theme Toggle ========== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-hover);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 0.25rem;
    margin-top: 0.75rem;
}

.theme-toggle button {
    flex: 1;
    background: none;
    border: none;
    padding: 0.3rem 0.5rem;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--sidebar-text);
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.theme-toggle button.active {
    background: var(--sidebar-active);
    color: #fff;
}

.theme-toggle button:hover:not(.active) {
    background: rgba(255,255,255,0.08);
}

/* ========== Cards ========== */
.welcome-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.welcome-card h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.welcome-card p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: border-color 0.15s, box-shadow 0.15s;
    color: var(--text);
}

.card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px var(--primary-light);
    text-decoration: none;
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.card p {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* ========== Tables ========== */
.table-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

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

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

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-hover);
}

/* ========== Upgrade Card ========== */
.upgrade-card {
    border: 2px dashed var(--primary);
    background: #f5f3ff;
}

[data-theme="dark"] .upgrade-card {
    background: rgba(129, 140, 248, 0.08);
}

.upgrade-card h3 { color: var(--primary); }

/* ========== Empty States ========== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.text-error { color: var(--danger); }
.text-muted { color: var(--text-muted); }

/* ========== Modals ========== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

[data-theme="dark"] .modal-overlay {
    background: rgba(0,0,0,0.6);
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    padding: 2rem;
    width: 100%;
    max-width: 480px;
}

.modal h2 {
    font-size: 1.125rem;
    margin-bottom: 1.25rem;
}

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

.modal .form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.modal .form-group input[type="text"],
.modal .form-group input[type="email"],
.modal .form-group input[type="url"],
.modal .form-group input[type="password"],
.modal .form-group input[type="number"],
.modal .form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--bg);
    color: var(--text);
}

.modal .form-group input:focus,
.modal .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ========== Small & Secondary Buttons ========== */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

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

.btn-danger:hover {
    background: #b91c1c;
    text-decoration: none;
}

[data-theme="dark"] .btn-danger:hover {
    background: #ef4444;
}

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

.btn-success:hover {
    background: #15803d;
    text-decoration: none;
}

.actions-cell {
    white-space: nowrap;
}

/* ========== Breadcrumb ========== */
.breadcrumb {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.breadcrumb a { color: var(--primary); }
.breadcrumb-sep { margin: 0 0.5rem; color: var(--text-muted); }

/* ========== Section Cards ========== */
.section-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.section-card h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
}

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

.section-header h2 { margin-bottom: 0; }

/* ========== Form Rows ========== */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row .form-group { margin-bottom: 0; }

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="date"] {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input:disabled {
    background: var(--bg);
    color: var(--text-muted);
}

.form-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-inline label { margin-bottom: 0; }

.form-message {
    margin-top: 0.75rem;
    font-size: 0.875rem;
}

.form-message.success { color: var(--success); }
.form-message.error { color: var(--danger); }

/* ========== Analytics ========== */
.analytics-controls {
    margin-bottom: 1.5rem;
}

.analytics-summary .stat-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 0.5rem;
}

.analytics-details { margin-top: 1.5rem; }

.stat-list .stat-items {
    list-style: none;
    padding: 0;
}

.stat-list .stat-items li {
    display: flex;
    justify-content: space-between;
    padding: 0.375rem 0;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.stat-list .stat-items li:last-child { border-bottom: none; }

/* ========== Tree Explorer ========== */
.tree-panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.tree-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-hover);
}

.tree-toolbar-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.tree-body {
    min-height: 200px;
}

/* Tree nodes */
.tree-node {
    border-bottom: 1px solid var(--border);
    transition: opacity 0.15s;
}

.tree-node:last-child {
    border-bottom: none;
}

.tree-node.drag-over {
    border-top: 2px solid var(--primary);
}

.tree-row {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
    gap: 0.375rem;
    user-select: none;
}

.tree-row:hover {
    background: var(--surface-hover);
}

/* Drag handle */
.tree-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    flex-shrink: 0;
    cursor: grab;
    color: var(--tree-line);
    font-size: 0.75rem;
    letter-spacing: -2px;
    opacity: 0;
    transition: opacity 0.1s;
}

.tree-drag-handle:active {
    cursor: grabbing;
}

.tree-row:hover .tree-drag-handle {
    opacity: 1;
}

.tree-row.selected {
    background: var(--primary-light);
}

.tree-indent {
    display: inline-block;
    width: 1.25rem;
    flex-shrink: 0;
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.625rem;
    transition: transform 0.15s;
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-toggle.leaf {
    visibility: hidden;
}

.tree-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 700;
    color: #fff;
}

.tree-icon.type-property  { background: #6366f1; }
.tree-icon.type-campaign  { background: #0891b2; }
.tree-icon.type-video     { background: #059669; }
.tree-icon.type-variation { background: #d97706; }

.tree-label {
    flex: 1;
    font-size: 0.875rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-label-name {
    font-weight: 500;
}

.tree-label-type {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.375rem;
}

.tree-badge {
    font-size: 0.6875rem;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    background: var(--surface-hover);
    color: var(--text-muted);
    border: 1px solid var(--border);
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    flex-shrink: 0;
}

.tree-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.1s;
    flex-shrink: 0;
}

.tree-row:hover .tree-actions {
    opacity: 1;
}

.tree-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.1s, color 0.1s;
}

.tree-action-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.tree-action-btn.danger:hover {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

/* Tree children container */
.tree-children {
    display: none;
}

.tree-children.open {
    display: block;
}

/* Empty children placeholder */
.tree-empty {
    display: flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-style: italic;
    gap: 0.375rem;
}

/* Inline add row */
.tree-inline-add {
    display: flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    gap: 0.375rem;
}

.tree-inline-add input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 0.8125rem;
    background: var(--surface);
    color: var(--text);
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-light);
}

.tree-inline-add .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Loading spinner for lazy-loaded children */
.tree-loading {
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.tree-loading::before {
    content: "";
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin-right: 0.5rem;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

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

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s;
    }

    .sidebar.open { transform: translateX(0); }

    .app-main { margin-left: 0; }

    .auth-card { padding: 1.5rem; }

    .card-grid { grid-template-columns: 1fr; }

    .tree-actions { opacity: 1; }

    .tree-drag-handle { opacity: 1; }
}
