/* ==========================================================================
   Attendance Tracking System — PerfexCRM-style Design
   ========================================================================== */

:root {
    --primary: #3e8ef7;
    --primary-hover: #2c7be5;
    --primary-light: rgba(62,142,247,0.08);
    --danger: #f96868;
    --danger-light: #fff0f0;
    --success: #46be8a;
    --success-light: #e8f8f1;
    --warning: #f2a654;
    --text: #3c4858;
    --text-secondary: #76838f;
    --heading: #37474f;
    --bg: #f3f4f8;
    --white: #ffffff;
    --border: #e4e7ed;
    --border-light: #f0f1f5;
    --sidebar-bg: #2c3e50;
    --sidebar-hover: #34495e;
    --sidebar-active: var(--primary);
    --sidebar-text: #a3b5c9;
    --sidebar-text-active: #ffffff;
    --sidebar-width: 250px;
    --topbar-height: 56px;
    --radius: 4px;
    --shadow: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --font: 'Open Sans', sans-serif;
    --font-ar: 'Tajawal', 'Open Sans', sans-serif;
}

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

html { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.6;
    min-height: 100vh;
}

[dir="rtl"] body {
    font-family: var(--font-ar);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform 0.25s ease;
    overflow-y: auto;
}

[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

.sidebar-header {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 60px;
    display: flex;
    align-items: center;
}

.sidebar-brand {
    display: block;
    text-decoration: none;
}

.sidebar-logo-img {
    max-width: 150px;
    height: auto;
    display: block;
    filter: brightness(0) invert(1);
}

.sidebar-nav {
    list-style: none;
    padding: 10px 0;
    flex: 1;
}

.sidebar-nav li { margin: 2px 8px; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.15s ease;
    font-size: 13px;
    font-weight: 500;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
}

.sidebar-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-icon svg {
    width: 18px;
    height: 18px;
}

.sidebar-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 8px 8px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-footer .sidebar-link {
    margin: 2px 0;
    font-size: 12px;
}

.sidebar-lang { color: var(--sidebar-text); }
.sidebar-lang:hover { color: #fff; }

.sidebar-logout { color: var(--danger); }
.sidebar-logout:hover { background: rgba(249,104,104,0.12); color: var(--danger); }

/* ==========================================================================
   Main wrapper
   ========================================================================== */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

[dir="rtl"] .main-wrapper {
    margin-left: 0;
    margin-right: var(--sidebar-width);
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
    background: var(--white);
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}

.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb-sep {
    margin: 0 8px;
    color: var(--text-secondary);
    opacity: 0.5;
}

[dir="rtl"] .breadcrumb-sep {
    transform: scaleX(-1);
}

/* ==========================================================================
   Content area
   ========================================================================== */
.content {
    padding: 24px;
    flex: 1;
}

/* ==========================================================================
   Page titles
   ========================================================================== */
h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--heading);
    margin-bottom: 20px;
}

h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--heading);
    margin-bottom: 14px;
}

/* ==========================================================================
   Cards (PerfexCRM panel style)
   ========================================================================== */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
}

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

.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 20px;
    text-align: center;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
}

/* ==========================================================================
   Tables (PerfexCRM style)
   ========================================================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: #f9fafb;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 14px;
    border-bottom: 2px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

[dir="rtl"] .data-table th {
    text-align: right;
}

.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text);
    vertical-align: middle;
}

[dir="rtl"] .data-table td {
    text-align: right;
}

.data-table tbody tr:hover {
    background: #f8f9fc;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ==========================================================================
   Badges (pill style)
   ========================================================================== */
.badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-warning {
    background: #fef7e8;
    color: var(--warning);
}

.badge-info {
    background: #e8f4fd;
    color: #3e8ef7;
}

.badge-default {
    background: #f0f1f5;
    color: var(--text-secondary);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    color: var(--text);
    background: var(--white);
    line-height: 1.5;
    font-family: inherit;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.btn-secondary {
    background: var(--white);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: #f5f6f8;
    border-color: #ccd1d9;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #e85656;
    border-color: #e85656;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.filter-form input,
.filter-form select {
    width: 100%;
    padding: 8px 12px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.filter-form input:focus,
.filter-form select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(62,142,247,0.12);
}

.input-inline {
    padding: 5px 10px !important;
    width: 180px !important;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
}

.input-inline:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(62,142,247,0.12);
}

/* Filter form */
.filter-form {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.filter-form input,
.filter-form select {
    width: auto;
    min-width: 160px;
}

/* ==========================================================================
   Pagination
   ========================================================================== */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 16px;
    justify-content: center;
}

.pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.15s ease;
}

.pagination a:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination a.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Inline forms */
.inline-form {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

/* ==========================================================================
   Raw payload
   ========================================================================== */
.raw-payload {
    background: #f5f7fa;
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 600px;
    overflow-x: auto;
    font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
    margin: 0;
    color: var(--text);
    border: 1px solid var(--border-light);
}

code {
    background: #f5f7fa;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
    color: var(--text);
}

/* ==========================================================================
   Helpers
   ========================================================================== */
.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid;
}

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border-color: #fdd;
}

.alert-success {
    background: var(--success-light);
    color: var(--success);
    border-color: #c3e6cb;
}

/* ==========================================================================
   Login page
   ========================================================================== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 50%, #3e8ef7 100%);
}

.login-card {
    background: var(--white);
    border-radius: 6px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    text-align: center;
}

.login-logo-img {
    max-width: 200px;
    height: auto;
    display: block;
    margin: 0 auto 20px;
}

.recaptcha-group {
    display: flex;
    justify-content: center;
}

.recaptcha-group .g-recaptcha {
    transform-origin: center;
}

.login-card h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--heading);
    margin-bottom: 4px;
}

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

.login-lang-switch {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10;
}

[dir="rtl"] .login-lang-switch {
    right: auto;
    left: 20px;
}

.login-lang-switch a {
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: var(--radius);
    padding: 6px 16px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
}

.login-lang-switch a:hover {
    background: rgba(255,255,255,0.25);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
    text-align: center;
    padding: 20px 24px;
    color: var(--text-secondary);
    font-size: 12px;
    border-top: 1px solid var(--border-light);
    margin-top: auto;
}

/* ==========================================================================
   RTL overrides
   ========================================================================== */
[dir="rtl"] .filter-form {
    flex-direction: row-reverse;
    flex-wrap: wrap;
}

[dir="rtl"] .inline-form {
    flex-direction: row-reverse;
}

[dir="rtl"] .pagination {
    flex-direction: row-reverse;
}

[dir="rtl"] .form-group label,
[dir="rtl"] .filter-group label {
    text-align: right;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 992px) {
    .sidebar-toggle { display: block; }

    .sidebar {
        transform: translateX(-100%);
    }
    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    body.sidebar-collapsed .sidebar {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

@media (max-width: 768px) {
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .filter-form, [dir="rtl"] .filter-form { flex-direction: column; align-items: stretch; }
    .filter-form input, .filter-form select { width: 100%; min-width: auto; }
    .stat-number { font-size: 26px; }
    .stats-grid { grid-template-columns: 1fr; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 10px; }
}
