/* assets/style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #ffffff;
    --bg-panel: #f8fafc;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #10b981;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.auth-panel {
    max-width: 400px;
    margin: 4rem auto;
}

.card {
    background: var(--bg-panel);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 { margin-bottom: 1.5rem; font-weight: 600; }
h3 { margin-bottom: 1rem; font-weight: 500; color: var(--text-muted); }

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

input, select, textarea {
    width: 100%;
    padding: 1rem; /* Slightly larger for easier touch */
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem; /* Clear font size to avoid zoom on iOS */
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem 1.5rem; /* Larger buttons */
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

button:hover { background: var(--primary-hover); }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }

.perm-required { display: none; }
.hidden { display: none !important; }

/* Grid layout for main dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
}

.nav-menu ul { list-style: none; }
.nav-menu li { margin-bottom: 0.5rem; }
.nav-menu a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-menu a:hover, .nav-menu a.active {
    background: var(--primary);
    color: white;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.matrix-table th, .matrix-table td {
    padding: 0.75rem;
    font-size: 0.875rem;
}

th {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.875rem;
}

tr:hover td { background: rgba(0, 0, 0, 0.02); }

/* Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--border);
}
.badge.success { background: rgba(16, 185, 129, 0.2); color: var(--success); }

toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 50;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-top: 0.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideLeft 0.3s ease-out;
}

@keyframes slideLeft {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

.search-results {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 0.5rem;
    background: var(--bg);
}

.search-result-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.search-result-item:hover { background: var(--border); }

/* Dynamic selection lists */
.selected-items { margin-top: 1rem; }
.selected-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

/* Utilities */
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.flex-row-gap {
    display: flex;
    gap: 0.5rem;
}
.flex-row-end {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}
.w-auto {
    width: auto !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .container { padding: 0.75rem; }
    header { 
        flex-direction: column; 
        align-items: center; 
        text-align: center;
        gap: 1rem; 
    }
    .brand { font-size: 1.15rem; }
    
    .dashboard-grid { 
        grid-template-columns: 1fr; 
        gap: 1rem; 
    }
    
    .nav-menu ul {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }
    .nav-menu li { margin-bottom: 0; white-space: nowrap; }
    
    .grid-2-col { grid-template-columns: 1fr; }
    .flex-row-gap { flex-direction: column; }
    .flex-row-end { flex-direction: column; align-items: stretch; }
    .w-auto { width: 100% !important; }
    
    .card { padding: 1rem; }
    
    /* Responsive Tables */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-top: 1rem;
        border: 1px solid var(--border);
        border-radius: 8px;
    }
    table { min-width: 600px; }
    
    input, select, button {
        font-size: 16px; /* Prevents auto-zoom on mobile safari */
    }

    #toast-container {
        right: 0.5rem;
        left: 0.5rem;
        bottom: 0.5rem;
    }
}

/* =====================
   Dashboard Statistics
   ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px -4px rgb(0 0 0 / 0.12);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-detail-grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.5rem;
}

/* Bar chart */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 140px;
}

.bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    height: 100%;
    justify-content: flex-end;
}

.bar-fill {
    width: 100%;
    background: var(--primary);
    border-radius: 6px 6px 0 0;
    min-height: 4px;
    transition: height 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.bar-fill:hover { background: var(--primary-hover); }

.bar-count {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.bar-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

/* Stats ranked list */
.stats-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stats-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stats-list-rank {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

.stats-list-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-list-bar {
    height: 6px;
    background: var(--primary);
    border-radius: 999px;
    opacity: 0.7;
    min-width: 4px;
    transition: width 0.5s ease;
}

.stats-list-count {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text);
    min-width: 24px;
    text-align: right;
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stats-detail-grid { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.5rem; }
}
