:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
    --secondary: #6b7280;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 6px -1px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-sm: 4px;
}

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

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

/* ========== NAVBAR ========== */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    min-height: 60px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-right: 24px;
    white-space: nowrap;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}

.nav-menu::-webkit-scrollbar {
    display: none;
}

.nav-menu a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-light);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-menu a:hover, .nav-menu a.active {
    color: var(--primary);
    background: #eff6ff;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
    white-space: nowrap;
}

.nav-user {
    color: var(--text-light);
    font-size: 0.85rem;
}

.nav-logout {
    color: var(--danger);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}

.nav-logout:hover { text-decoration: underline; }

/* ========== MAIN CONTENT ========== */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 1.6rem;
    line-height: 1.2;
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-light);
    font-size: 0.95rem;
}

.share-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.compact-select {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text);
    font: inherit;
}

.share-panel {
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.2fr);
    gap: 16px;
    align-items: center;
    background: #ecfeff;
    border: 1px solid #a5f3fc;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.share-panel[hidden] {
    display: none;
}

.share-panel p {
    color: var(--text-light);
    font-size: 0.88rem;
    margin-top: 2px;
}

.share-link-row {
    display: flex;
    gap: 8px;
    min-width: 0;
}

.share-link-row input {
    min-width: 0;
    flex: 1;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    color: var(--text);
}

/* ========== CARDS ========== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ========== STATS GRID ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.stat-icon.blue { background: #dbeafe; color: var(--primary); }
.stat-icon.green { background: #dcfce7; color: var(--success); }
.stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }

.stat-info h3 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
}

.stat-info p {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* ========== TABLES ========== */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:hover { background: #f9fafb; }

/* ========== BADGES ========== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #cffafe; color: #155e75; }
.badge-secondary { background: #f3f4f6; color: #4b5563; }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
    min-height: 34px;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }

.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #4b5563; }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ========== FORMS ========== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* ========== LOGIN ========== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    padding: 20px;
}

.login-box {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: min(100%, 420px);
    max-width: 420px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.login-box .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 28px;
    font-size: 0.9rem;
}

.login-icon {
    text-align: center;
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 16px;
}

.login-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: #f3f4f6;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 18px;
}

.login-switch button {
    border: none;
    background: transparent;
    color: var(--text-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 8px 10px;
}

.login-switch button.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 0.9rem;
}

.checkbox-line input {
    width: 16px;
    height: 16px;
}

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

.modal-overlay.active { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.modal-body { padding: 20px; }

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ========== FLASH ========== */
.flash {
    max-width: 1400px;
    margin: 16px auto 0;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}

.flash-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

.flash button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: inherit;
}

.secret-flash {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.secret-flash code {
    background: rgba(255,255,255,0.75);
    border: 1px solid currentColor;
    border-radius: var(--radius-sm);
    color: inherit;
    padding: 4px 8px;
}

.secret-flash .btn {
    color: white;
}

.secret-display {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) auto;
    gap: 14px;
    align-items: center;
}

.secret-display p {
    color: var(--text-light);
    font-size: 0.86rem;
    margin-top: 2px;
}

.secret-display code {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 8px 10px;
    word-break: break-all;
}

/* ========== LOADING ========== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 300;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}

.loading-overlay.active { display: flex; }

/* ========== GRID ========== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 500;
    transform: translateY(10px);
    opacity: 0;
    background: #111827;
    color: #fff;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 10px 14px;
    font-size: 0.9rem;
    transition: opacity 0.18s, transform 0.18s;
}

.toast.active {
    opacity: 1;
    transform: translateY(0);
}

.public-shell {
    max-width: 1180px;
    margin: 0 auto;
}

.public-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 24px;
    padding: 24px 0 4px;
}

.public-header h1 {
    font-size: 2rem;
    line-height: 1.15;
    margin: 4px 0 8px;
}

.public-header p {
    color: var(--text-light);
}

.public-kicker,
.readonly-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
    font-size: 0.86rem;
    font-weight: 700;
}

.readonly-badge {
    color: #155e75;
    background: #cffafe;
    border: 1px solid #67e8f9;
    border-radius: 999px;
    padding: 6px 12px;
    white-space: nowrap;
}

.readonly-badge.can-operate {
    color: #166534;
    background: #dcfce7;
    border-color: #86efac;
}

.muted-empty {
    color: var(--text-light);
    padding: 20px;
}

/* ========== TABS ========== */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-weight: 500;
    color: var(--text-light);
}
.tab.active { color: var(--primary); border-color: var(--primary); }
.tab:hover { color: var(--primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
    .nav-brand { width: 100%; margin-right: 0; justify-content: center; }
    .nav-menu { order: 3; width: 100%; gap: 2px; }
    .nav-menu a { padding: 6px 10px; font-size: 0.8rem; }
    .nav-right { width: 100%; justify-content: space-between; }
    .main-content { padding: 12px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .page-header,
    .public-header {
        flex-direction: column;
    }
    .share-actions,
    .share-link-row {
        width: 100%;
    }
    .share-actions .btn,
    .share-link-row .btn,
    .compact-select {
        flex: 1;
    }
    .share-panel {
        grid-template-columns: 1fr;
    }
    .secret-display {
        grid-template-columns: 1fr;
    }
    .login-box {
        padding: 28px 22px;
    }
}

@media (max-width: 520px) {
    .stats-grid { grid-template-columns: 1fr; }
    .card-header {
        align-items: flex-start;
        flex-direction: column;
    }
    .toast {
        right: 12px;
        bottom: 12px;
        left: 12px;
        text-align: center;
    }
}

/* ========== UTILITIES ========== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mt-2 { margin-top: 16px; }
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-2 { gap: 12px; }
.w-full { width: 100%; }
