/* PALETTO - iOS-Style Design System */
:root {
    --primary: #007AFF;
    --primary-light: #E3F2FF;
    --success: #34C759;
    --success-light: #E8F9ED;
    --warning: #FF9500;
    --warning-light: #FFF4E5;
    --danger: #FF3B30;
    --danger-light: #FFEBEA;
    --gray-50: #F9FAFB;
    --gray-100: #F2F2F7;
    --gray-200: #E5E5EA;
    --gray-300: #D1D1D6;
    --gray-400: #AEAEB2;
    --gray-500: #8E8E93;
    --gray-600: #636366;
    --gray-700: #48484A;
    --gray-800: #3A3A3C;
    --gray-900: #1C1C1E;
    --bg: #F2F2F7;
    --card: #FFFFFF;
    --text: #1C1C1E;
    --text-secondary: #8E8E93;
    --radius: 14px;
    --radius-lg: 20px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --transition: all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Login Screen */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #007AFF 100%);
}

.login-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 48px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    animation: slideUp 0.5s ease;
}

.login-logo {
    font-size: 56px;
    margin-bottom: 8px;
    color: var(--primary);
}

.login-logo i {
    font-size: 56px;
}

/* Bootstrap Icons Global Styling */
.bi { vertical-align: -0.125em; }

.nav-icon .bi,
.stat-icon .bi { font-size: inherit; }

.sidebar-brand-icon .bi { font-size: 28px; }

.stat-icon .bi {
    color: inherit;
}

.stat-icon.blue .bi { color: var(--primary); }
.stat-icon.green .bi { color: var(--success); }
.stat-icon.orange .bi { color: var(--warning); }
.stat-icon.red .bi { color: var(--danger); }

.search-result-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--gray-100);
    color: var(--gray-600);
    flex-shrink: 0;
}

.empty-state-icon .bi { font-size: 48px; }

.photo-upload-icon .bi { font-size: 32px; }

.card-title .bi {
    margin-right: 6px;
    font-size: 18px;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text);
}

.login-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* Form Elements */
.form-group {
    margin-bottom: 18px;
    text-align: left;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    background: var(--gray-50);
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
}

.form-input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(0,122,255,0.1);
}

.form-select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    background: var(--gray-50);
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
    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 fill='%238E8E93' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

.form-select:focus {
    border-color: var(--primary);
    background-color: white;
}

textarea.form-input {
    min-height: 100px;
    resize: vertical;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: #0066D6; }

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

.btn-warning {
    background: var(--warning);
    color: white;
}

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

.btn-secondary {
    background: var(--gray-100);
    color: var(--text);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 10px;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 18px;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 10px;
    font-size: 18px;
}

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

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--card);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--gray-200);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand-icon {
    font-size: 32px;
}

.sidebar-brand-text h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.sidebar-brand-text span {
    font-size: 12px;
    color: var(--text-secondary);
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 4px;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--text);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-item .nav-icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}

.sidebar-user-info h4 {
    font-size: 14px;
    font-weight: 600;
}

.sidebar-user-info span {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: capitalize;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    min-height: 100vh;
}

/* Top Bar */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

.topbar-title {
    font-size: 20px;
    font-weight: 700;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    position: relative;
}

.search-input {
    padding: 10px 16px 10px 40px;
    border: 2px solid var(--gray-200);
    border-radius: 12px;
    font-size: 14px;
    width: 280px;
    background: var(--gray-50);
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}

.search-input:focus {
    border-color: var(--primary);
    background: white;
    width: 340px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 16px;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    margin-top: 8px;
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}

.search-results.active { display: block; }

.search-result-group { padding: 8px; }

.search-result-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    padding: 8px 12px 4px;
    letter-spacing: 0.5px;
}

.search-result-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.search-result-item:hover { background: var(--gray-100); }

/* Notification Bell */
.notif-btn {
    position: relative;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    transition: var(--transition);
}

.notif-btn:hover { background: var(--gray-100); }

.notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Page Content */
.page-content {
    padding: 24px;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-lg); }

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

.card-title {
    font-size: 17px;
    font-weight: 700;
}

.card-body { padding: 24px; }

.card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* Stat Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 12px;
}

.stat-icon.blue { background: var(--primary-light); }
.stat-icon.green { background: var(--success-light); }
.stat-icon.orange { background: var(--warning-light); }
.stat-icon.red { background: var(--danger-light); }

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Tables */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.table th {
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.table tr:hover td { background: var(--gray-50); }
.table tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: var(--success-light); color: #1B7A34; }
.badge-warning { background: var(--warning-light); color: #8B5E00; }
.badge-danger { background: var(--danger-light); color: #C62828; }
.badge-primary { background: var(--primary-light); color: #0055B8; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.95);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: 24px 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: var(--gray-100);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-500);
    transition: var(--transition);
}

.modal-close:hover { background: var(--gray-200); }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 0 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--card);
    border-radius: 12px;
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 420px;
    animation: slideIn 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    border-left: 4px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

.toast-close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 16px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 24px;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar-spacer { flex: 1; }

/* Grid Layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* Photo Upload */
.photo-upload {
    border: 2px dashed var(--gray-300);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.photo-upload:hover { border-color: var(--primary); background: var(--primary-light); }

.photo-upload input { display: none; }

.photo-upload-icon {
    font-size: 36px;
    color: var(--gray-400);
    margin-bottom: 8px;
}

.photo-upload-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.photo-preview {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: 12px;
}

/* Animations */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in { animation: fadeIn 0.3s ease; }
.slide-up { animation: slideUp 0.4s ease; }

/* Loading Spinner */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}

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

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
}

/* Notification Panel */
.notif-panel {
    position: fixed;
    top: 0;
    right: -380px;
    width: 380px;
    height: 100vh;
    background: var(--card);
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    z-index: 200;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.notif-panel.active { right: 0; }

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

.notif-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.notif-item {
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.notif-item:hover { background: var(--gray-50); }
.notif-item.unread { background: var(--primary-light); border-left-color: var(--primary); }

.notif-item-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.notif-item-msg {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.notif-item-time {
    font-size: 11px;
    color: var(--gray-400);
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    display: none;
}

.sidebar-overlay.active { display: block; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }

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

    .menu-toggle { display: block; }

    .topbar { padding: 12px 16px; }

    .search-input { width: 100%; }
    .search-input:focus { width: 100%; }

    .search-box {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding: 12px;
        background: var(--card);
        z-index: 60;
        display: none;
    }

    .search-box.active {
        display: block;
    }

    .page-content { padding: 16px; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    .stat-card { padding: 16px; }
    .stat-value { font-size: 24px; }

    .toolbar { gap: 8px; }

    .modal { margin: 10px; max-height: 95vh; }

    .table td, .table th { padding: 10px 12px; font-size: 13px; }

    .login-card { padding: 32px 24px; }

    .notif-panel { width: 100%; right: -100%; }

    .topbar-title { font-size: 17px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 11px; }
    .btn { padding: 12px 18px; font-size: 14px; }
}

/* Chart Containers */
.chart-container {
    position: relative;
    width: 100%;
    padding: 16px;
}

.chart-container canvas {
    max-height: 280px;
}

.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.chart-row-3 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .chart-row,
    .chart-row-3 {
        grid-template-columns: 1fr;
    }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* PWA Standalone Mode */
@media (display-mode: standalone) {
    .topbar {
        padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    }
    .sidebar {
        padding-top: env(safe-area-inset-top, 0px);
    }
    .login-container {
        padding-top: env(safe-area-inset-top, 0px);
    }
}

/* Mobile Touch Optimizations */
@media (max-width: 768px) {
    .btn { min-height: 44px; }
    .nav-item { min-height: 44px; }
    .form-input, .form-select { min-height: 44px; font-size: 16px; }
    .table td { padding: 12px 10px; }

    .topbar-right .search-box { display: none; }
    .topbar-right .search-toggle { display: inline-flex; }
}
