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

:root {
    --white: #ffffff;
    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #eff6ff;
    --red: #ef4444;
    --green: #10b981;
    --blue: #3b82f6;
    --orange: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; }

.sketch-overlay { display: none; }

/* === Cards & Borders === */
.sketch-border {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.sketch-border-sm {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.sketch-border-right { border-right: 1px solid var(--border); }
.sketch-border-bottom { border-bottom: 1px solid var(--border); }

/* === Typography === */
.sketch-title { font-size: 1.5rem; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.sketch-title::after { display: none; }
.sketch-subtitle { font-size: 1.125rem; font-weight: 600; color: var(--text); }
.sketch-label { font-size: 0.875rem; font-weight: 500; color: var(--text); display: block; margin-bottom: 6px; }
.sketch-signature { font-size: 0.8rem; color: var(--text-muted); }
.sketch-help { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.sketch-empty { padding: 48px 20px; color: var(--text-muted); font-size: 0.95rem; text-align: center; }
.sketch-code {
    background: var(--border-light); padding: 2px 8px; border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.8rem; color: var(--text);
}
.sketch-code-sm {
    background: var(--border-light); padding: 1px 6px; border-radius: 3px;
    font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.78rem;
    max-width: 200px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* === Forms === */
.sketch-input {
    background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 9px 12px; font-family: var(--font); font-size: 0.875rem; color: var(--text);
    width: 100%; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: none;
}
.sketch-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.sketch-input-sm {
    background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 6px 10px; font-family: var(--font); font-size: 0.85rem; color: var(--text); outline: none;
}
.sketch-input-sm:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.sketch-textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
.sketch-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px;
}
.sketch-color { height: 40px; padding: 3px; cursor: pointer; }
.sketch-checkbox { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin-right: 6px; }

/* === Buttons === */
.sketch-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--accent); color: var(--white); border: 1px solid var(--accent);
    border-radius: var(--radius-sm); padding: 9px 20px;
    font-family: var(--font); font-size: 0.875rem; font-weight: 500;
    cursor: pointer; transition: all 0.15s; text-decoration: none; white-space: nowrap;
    box-shadow: none;
}
.sketch-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: none; box-shadow: none; }
.sketch-btn:active { transform: none; box-shadow: none; }
.sketch-btn-sm {
    display: inline-flex; align-items: center; gap: 4px;
    background: var(--accent); color: var(--white); border: 1px solid var(--accent);
    border-radius: var(--radius-sm); padding: 5px 12px;
    font-family: var(--font); font-size: 0.8125rem; font-weight: 500;
    cursor: pointer; transition: all 0.15s; text-decoration: none; white-space: nowrap;
    box-shadow: none;
}
.sketch-btn-sm:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: none; box-shadow: none; }
.sketch-btn-sm:active { transform: none; box-shadow: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--white); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: var(--white); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--border-light); border-color: var(--text-secondary); }

.w-full { width: 100%; }
.text-center { text-align: center; }
.half { flex: 1; min-width: 0; }

/* === Login Page === */
.login-page {
    display: flex; justify-content: center; align-items: center; min-height: 100vh;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8ecf4 100%);
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--white); padding: 36px; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.login-header { text-align: center; margin-bottom: 28px; }
.logo-sketch { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; }
.logo-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    font-size: 22px; color: var(--white); background: var(--accent);
    transform: none; box-shadow: none;
}
.logo-text { font-size: 1.75rem; font-weight: 700; color: var(--text); letter-spacing: -0.03em; }
.login-subtitle { font-size: 0.875rem; color: var(--text-secondary); }
.login-footer { text-align: center; margin-top: 20px; }
.login-form .form-group { margin-bottom: 18px; }
.login-form .sketch-btn { padding: 11px; font-size: 0.9rem; }

/* === Admin Layout === */
.admin-body { overflow: hidden; }
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; flex-shrink: 0; background: var(--white);
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
    height: 100vh; z-index: 100; border-right: 1px solid var(--border);
    box-shadow: 1px 0 3px rgba(0,0,0,0.03);
}
.sidebar-header {
    padding: 20px 20px 16px; display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header .logo-icon { width: 32px; height: 32px; font-size: 16px; border-radius: 6px; }
.sidebar-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 20px;
    color: var(--text-secondary); text-decoration: none; font-size: 0.875rem; font-weight: 500;
    border-left: 3px solid transparent; transition: all 0.15s; margin: 2px 0;
}
.nav-item:hover { background: var(--accent-light); color: var(--accent); border-left-color: var(--accent); }
.nav-item.active { background: var(--accent-light); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); text-align: center; }

.admin-main { margin-left: 240px; flex: 1; height: 100vh; display: flex; flex-direction: column; overflow-y: auto; min-width: 0; }
.admin-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 28px; background: var(--white);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-badge { font-size: 0.75rem !important; }
.header-mode { font-size: 0.85rem; color: var(--text-secondary); }
.header-actions { display: flex; gap: 8px; }
.content-body { padding: 24px 28px 40px; flex: 1; }

/* === Stats Grid === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
    background: var(--white); padding: 22px 24px; display: flex; align-items: center; gap: 16px;
    border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon { font-size: 1.75rem; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: var(--accent-light); border-radius: var(--radius-sm); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; color: var(--text); letter-spacing: -0.02em; }
.stat-label { font-size: 0.8125rem; color: var(--text-secondary); }

/* === Section === */
.section { margin-bottom: 28px; }
.section-title { margin-bottom: 16px; }

/* === Table === */
.table-container {
    background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow-sm);
}
.sketch-table { width: 100%; border-collapse: collapse; }
.sketch-table th {
    padding: 10px 16px; text-align: left; font-size: 0.75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
    background: var(--border-light); color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.sketch-table td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); font-size: 0.875rem; }
.sketch-table tr:last-child td { border-bottom: none; }
.sketch-table tr:hover td { background: #f8fafc; }
.action-cell { display: flex; gap: 6px; flex-wrap: nowrap; }

/* === Small Buttons === */
.btn-sm {
    display: inline-flex; align-items: center; padding: 4px 10px; font-size: 0.78rem;
    border-radius: var(--radius-sm); border: 1px solid var(--border); text-decoration: none;
    font-weight: 500; cursor: pointer; transition: all 0.15s; color: var(--text-secondary);
    background: var(--white); gap: 4px;
}
.btn-sm:hover { border-color: var(--text-secondary); color: var(--text); }
.btn-edit { color: var(--blue); border-color: rgba(59,130,246,0.3); }
.btn-edit:hover { background: var(--accent-light); border-color: var(--blue); color: var(--blue); }
.btn-link { color: var(--accent); border-color: rgba(59,130,246,0.3); }
.btn-link:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.btn-view { color: var(--green); border-color: rgba(16,185,129,0.3); }
.btn-view:hover { background: rgba(16,185,129,0.06); border-color: var(--green); color: var(--green); }
.btn-delete { color: var(--red); border-color: rgba(239,68,68,0.3); }
.btn-delete:hover { background: rgba(239,68,68,0.06); border-color: var(--red); color: var(--red); }
.btn-copy {
    padding: 4px 10px; background: var(--white); border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer; font-size: 0.78rem;
    color: var(--text-secondary); white-space: nowrap; transition: all 0.15s;
}
.btn-copy:hover { background: var(--border-light); border-color: var(--text-secondary); }

/* === Badges === */
.badge { display: inline-block; padding: 2px 8px; font-size: 0.72rem; font-weight: 600; border-radius: 100px; }
.badge-active { background: rgba(16,185,129,0.08); color: var(--green); }
.badge-inactive { background: rgba(239,68,68,0.08); color: var(--red); }

/* === Alerts === */
.alert { padding: 10px 14px; margin-bottom: 16px; font-size: 0.85rem; border-radius: var(--radius-sm); }
.alert-success { background: rgba(16,185,129,0.06); color: #065f46; border: 1px solid rgba(16,185,129,0.2); }
.alert-error { background: rgba(239,68,68,0.06); color: #991b1b; border: 1px solid rgba(239,68,68,0.2); }

/* === Forms === */
.form-section { background: var(--white); padding: 24px; margin-bottom: 20px; border: 1px solid var(--border); border-radius: var(--radius); }
.form-section-title { margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); font-size: 1rem; font-weight: 600; }
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 16px; }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }
.form-label { display: flex; align-items: center; gap: 6px; }

/* === Copy Field === */
.copy-field { display: flex; align-items: center; gap: 8px; }
.copy-field .form-input, .copy-field .sketch-input-sm { flex: 1; min-width: 0; font-size: 0.82rem; }
.copy-label { font-size: 0.85rem; white-space: nowrap; color: var(--text-secondary); font-weight: 500; }

/* === Links Toolbar === */
.links-toolbar { display: flex; gap: 20px; padding-bottom: 16px; margin-bottom: 20px; flex-wrap: wrap; }

.sort-handle { cursor: grab; color: var(--text-muted); font-size: 0.85rem; }
.link-title { font-weight: 500; }

/* === Modal === */
.modal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 1000; background: var(--white); padding: 28px; width: 90%; max-width: 500px;
    border-radius: var(--radius-lg); box-shadow: 0 25px 50px -12px rgba(0,0,0,0.2);
    border: 1px solid var(--border);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-close { font-size: 1.3rem; color: var(--text-muted); text-decoration: none; transition: color 0.15s; }
.modal-close:hover { color: var(--text); }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); z-index: 999; }

/* === QR Preview === */
.qr-preview-wrapper { display: flex; justify-content: center; padding: 20px; background: var(--white); border: 1px dashed var(--border); border-radius: var(--radius); }
#qrcode { padding: 12px; position: relative; }
#qrcode canvas, #qrcode img { display: block; margin: 0 auto; }

/* === Error Page === */
.error-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #f0f4ff 0%, #e8ecf4 100%); }
.error-card { background: var(--white); padding: 48px; text-align: center; max-width: 400px; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.error-icon { font-size: 3rem; color: var(--red); margin-bottom: 16px; }
.error-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.error-card p { color: var(--text-secondary); font-size: 0.9rem; }

/* === Desktop Optimizations (≥1024px) === */
@media (min-width: 1024px) {
    .sidebar {
        width: 260px;
        box-shadow: 1px 0 4px rgba(0,0,0,0.03);
    }
    .sidebar-header { padding: 22px 24px 16px; }
    .sidebar-header h2 { font-size: 1.15rem; }
    .sidebar-nav { padding: 16px 0; }
    .nav-item { padding: 11px 24px; font-size: 0.9rem; }
    .sidebar-footer { padding: 18px 24px; font-size: 0.82rem; }

    .admin-header {
        padding: 18px 36px;
        background: rgba(255,255,255,0.92);
        backdrop-filter: blur(8px);
    }
    .admin-header .page-title { font-size: 1.4rem; }

    .content-body {
        padding: 32px 36px 48px;
        max-width: 1280px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
    .stat-card { padding: 26px 28px; }

    .sketch-table th { padding: 12px 20px; font-size: 0.78rem; }
    .sketch-table td { padding: 14px 20px; font-size: 0.88rem; }

    .form-section { padding: 28px 32px; }
    .form-row { gap: 24px; }

    .links-toolbar { gap: 28px; }

    .modal { padding: 36px; max-width: 560px; }

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

/* === Tablet (768–1023px) === */
@media (min-width: 768px) and (max-width: 1023px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .content-body { padding: 24px 24px 40px; }
    .admin-header { padding: 16px 24px; }
    .form-row { gap: 16px; }
}

/* === Narrow Tablet / Mobile === */
@media (max-width: 767px) {
    .sidebar { width: 60px; }
    .sidebar-header h2, .sidebar-footer, .nav-item span:not(.nav-icon) { display: none; }
    .sidebar-header { justify-content: center; padding: 12px; }
    .sidebar-header .logo-icon { width: 28px; height: 28px; font-size: 14px; }
    .nav-item { justify-content: center; padding: 12px; border-left: none; }
    .nav-item:hover, .nav-item.active { border-left: none; }
    .admin-main { margin-left: 60px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 16px; gap: 12px; }
    .stat-value { font-size: 1.3rem; }
    .stat-icon { width: 36px; height: 36px; font-size: 1.3rem; }
    .form-row { flex-direction: column; gap: 0; }
    .admin-header { flex-direction: column; gap: 10px; align-items: flex-start; padding: 12px 16px; }
    .header-actions { width: 100%; }
    .content-body { padding: 16px; }
    .form-section { padding: 16px; }
    .table-container { overflow-x: auto; }
    .sketch-table th,
    .sketch-table td { padding: 8px 10px; font-size: 0.78rem; white-space: nowrap; }
    .action-cell { flex-wrap: wrap; }
    .links-toolbar { flex-direction: column; gap: 12px; }
    .copy-field { flex-direction: column; align-items: stretch; }
    .modal { width: 95%; padding: 20px; }
    .sketch-title { font-size: 1.2rem; }
    .header-mode { display: none; }
}

/* === Small Mobile === */
@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
    .sidebar { width: 100%; height: auto; position: fixed; bottom: 0; left: 0; top: auto; flex-direction: row; overflow-x: auto; border-right: none; border-top: 1px solid var(--border); z-index: 100; }
    .sidebar-header, .sidebar-footer { display: none !important; }
    .sidebar-nav { display: flex !important; flex-direction: row; padding: 0; }
    .nav-item { flex: 1; justify-content: center; padding: 10px 4px; font-size: 0.7rem; border-left: none; border-top: 2px solid transparent; margin: 0; }
    .nav-item:hover, .nav-item.active { border-top-color: var(--accent); border-left: none; }
    .nav-icon { font-size: 1.1rem; }
    .nav-item span:not(.nav-icon) { display: block; font-size: 0.6rem; }
    .admin-main { height: calc(100vh - 56px); }
    .sidebar { width: 0; overflow: hidden; border-right: none; }
    .sidebar-header { padding: 0; }
    .sidebar-nav, .sidebar-footer { display: none; }
    .sketch-table td,
    .sketch-table th { padding: 6px 8px; font-size: 0.72rem; }
    .btn-sm { font-size: 0.72rem; padding: 3px 8px; }
}

/* === Smooth scrollbar for tables === */
.table-container::-webkit-scrollbar { height: 6px; }
.table-container::-webkit-scrollbar-track { background: transparent; }
.table-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.table-container::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Better focus styles for accessibility === */
.sketch-btn:focus-visible,
.sketch-input:focus-visible,
.btn-sm:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* === Print optimization === */
@media print {
    .sidebar, .admin-header, .btn-sm, .btn-copy, .form-actions { display: none !important; }
    .content-body { padding: 20px !important; }
    .table-container { border: 1px solid #ddd; box-shadow: none; }
}
