:root {
    --primary: #714B67;
    --primary-dark: #5a3c53;
    --primary-light: #f3edf2;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --gray-50: #f8f9fa;
    --gray-100: #e9ecef;
    --gray-200: #dee2e6;
    --gray-500: #6c757d;
    --gray-700: #495057;
    --gray-900: #212529;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
/* Header brand */
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-logo {
    height: 32px;
    width: auto;
    border-radius: 4px;
}
.header h1 { font-size: 18px; font-weight: 600; }
.header .user-info { font-size: 14px; opacity: 0.9; }
.header button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 6px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}
.header button:hover { background: rgba(255,255,255,0.3); }

/* Tab Bar */
.tab-bar {
    background: white;
    border-bottom: 2px solid var(--gray-200);
    display: flex;
    padding: 0 20px;
    position: sticky;
    top: 48px;
    z-index: 99;
}
.tab-btn {
    background: none;
    border: none;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Container */
.container { max-width: 960px; margin: 0 auto; padding: 20px; }

/* Inline add row */
.add-row { margin-bottom: 4px; }
.add-row-fields {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.add-row-fields .form-group { flex: 1; min-width: 120px; }
.add-row-fields .form-group:last-child { flex: 0; min-width: auto; }

/* Searchable select */
.searchable-select { position: relative; }
.searchable-select input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    background: white;
    transition: border-color 0.2s;
}
.searchable-select input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.ss-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
    margin-top: 2px;
}
.ss-dropdown.open { display: block; }
.ss-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
}
.ss-option:hover { background: var(--primary-light); color: var(--primary); }
.ss-empty { padding: 8px 12px; color: var(--gray-500); font-size: 13px; }

/* Table scroll for mobile */
.table-scroll { overflow-x: auto; }

/* Description cell */
.ts-table .desc-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
}

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s;
    background: white;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; min-height: 60px; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    width: 100%;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 6px 12px; font-size: 12px; width: auto; }

/* Alerts */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}
.alert.show { display: block; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* Login screen */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card {
    background: white;
    border-radius: 12px;
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
/* Login branding */
.login-brand {
    text-align: center;
    margin-bottom: 8px;
}
.login-logo {
    height: 64px;
    width: auto;
    margin-bottom: 12px;
    border-radius: 8px;
}
.login-brand h2 {
    color: var(--primary);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 4px;
}
.brand-tagline {
    font-size: 13px;
    color: var(--gray-500);
    font-weight: 400;
}
.brand-company-name {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
    font-weight: 500;
}
.login-card h2 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 22px;
}
.login-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 28px;
}

/* Timesheet table */
.ts-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ts-table th {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 2px solid var(--gray-200);
    color: var(--gray-500);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ts-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--gray-100);
}
.ts-table tr:hover td { background: var(--gray-50); }
.ts-table .actions { white-space: nowrap; }
.ts-table .actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 16px;
}
.ts-table .actions button:hover { background: var(--gray-100); }
.ts-table .hours { font-weight: 600; color: var(--primary); }

/* Inline edit */
.ts-table tr.editing td { background: var(--primary-light); }
.inline-input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    font-size: 13px;
    background: white;
}
.inline-input:focus { outline: none; border-color: var(--primary); }
.inline-hours { width: 70px; }
.inline-date { width: 120px; }
.ts-table .actions .action-save { color: var(--success); }

/* Validated rows */
.ts-table tr.validated td {
    background: var(--gray-50);
    color: var(--gray-500);
}
.ts-table tr.validated .hours { color: var(--gray-500); }
.validated-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #d4edda;
    color: #155724;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

/* State badges */
.state-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
}
.state-draft { background: var(--gray-100); color: var(--gray-700); }
.state-waiting { background: #fff3cd; color: #856404; }
.state-approved { background: #d4edda; color: #155724; }
.state-refused { background: #f8d7da; color: #721c24; }

/* Leave Balances */
.balance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
.balance-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 12px;
}
.balance-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}
.balance-numbers { margin-bottom: 6px; }
.balance-remaining {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}
.balance-total {
    font-size: 13px;
    color: var(--gray-500);
}
.balance-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}
.balance-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}

/* Leave days badge */
.leave-days-badge {
    padding: 10px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    text-align: center;
    color: var(--gray-500);
    background: var(--gray-50);
    font-weight: 600;
    min-width: 70px;
}
.leave-days-badge.has-value {
    color: var(--primary);
    background: var(--primary-light);
    border-color: var(--primary);
}

/* File input */
input[type="file"] {
    padding: 8px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 13px;
    background: white;
    width: 100%;
    cursor: pointer;
}
input[type="file"]::-webkit-file-upload-button {
    background: var(--primary-light);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    margin-right: 8px;
}

/* Priority colors */
.priority-low { color: #17a2b8; }
.priority-medium { color: #fd7e14; font-weight: 600; }
.priority-high { color: var(--danger); font-weight: 700; }

/* Ticket subject */
.ticket-subject {
    font-weight: 600;
    color: var(--primary);
}
.ticket-row:hover .ticket-subject { text-decoration: underline; }

/* Ticket detail */
.ticket-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 13px;
    color: var(--gray-700);
    margin-bottom: 12px;
}
.ticket-meta strong { color: var(--gray-500); }
.ticket-description {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 12px;
    font-size: 13px;
    margin-top: 8px;
    line-height: 1.5;
}

/* Messages */
.message-item {
    border-left: 3px solid var(--gray-200);
    padding: 8px 12px;
    margin-bottom: 8px;
    font-size: 13px;
}
.message-note {
    border-left-color: var(--warning);
    background: #fffde7;
}
.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}
.message-author {
    font-weight: 600;
    color: var(--gray-700);
}
.message-date {
    font-size: 12px;
    color: var(--gray-500);
}
.message-body {
    color: var(--gray-900);
    line-height: 1.5;
}
.message-body p { margin-bottom: 4px; }

/* Group headers */
.group-header {
    background: var(--primary-light);
    padding: 8px 10px;
    font-weight: 600;
    font-size: 13px;
    color: var(--primary);
    border-radius: var(--radius);
    margin-top: 12px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.group-header:first-child { margin-top: 0; }
.group-header .group-total {
    font-size: 12px;
    color: var(--gray-700);
    font-weight: 500;
}
.group-header .collapse-icon {
    font-size: 12px;
    transition: transform 0.2s;
}
.group-header.collapsed .collapse-icon { transform: rotate(-90deg); }
.group-content.collapsed { display: none; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-100);
}
.pagination button {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--gray-700);
    transition: all 0.2s;
}
.pagination button:hover { background: var(--gray-50); border-color: var(--primary); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 12px; color: var(--gray-500); margin: 0 8px; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* Loading */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 480px) {
    .container { padding: 12px; }
    .card { padding: 16px; }
    .login-card { margin: 12px; padding: 28px 20px; }
    .ts-table { font-size: 12px; }
    .ts-table th, .ts-table td { padding: 8px 4px; }
    .tab-btn { padding: 10px 14px; font-size: 13px; }
    .balance-grid { grid-template-columns: 1fr 1fr; }
    .ticket-meta { gap: 8px; }
}

/* Footer */
.footer {
    text-align: center;
    padding: 16px 20px;
    font-size: 12px;
    color: var(--gray-500);
    border-top: 1px solid var(--gray-200);
    margin-top: 20px;
}
.footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.footer a:hover { text-decoration: underline; }

/* Screen visibility */
.screen { display: none; }
.screen.active { display: block; }
