/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f6fa;
    color: #2d3436;
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Navbar ===== */
.navbar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.nav-brand {
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
}

.nav-menu {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-link {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-link:hover {
    background: rgba(255,255,255,0.15);
    color: white;
}

.nav-admin {
    background: rgba(255,193,7,0.2);
    color: #ffe082;
}

.nav-admin:hover {
    background: rgba(255,193,7,0.35);
}

.nav-logout {
    background: rgba(239,83,80,0.2);
}

.nav-logout:hover {
    background: rgba(239,83,80,0.4);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
}

/* ===== Main Content ===== */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* ===== Cards ===== */
.card {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #2d3436;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.25rem 1rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #667eea;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: #636e72;
    margin-top: 0.25rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: #2d3436;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid #dfe6e9;
    border-radius: 10px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

.form-input::placeholder {
    color: #b2bec3;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    -webkit-appearance: none;
    min-height: 48px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102,126,234,0.3);
}

.btn-success {
    background: linear-gradient(135deg, #00b894 0%, #00a085 100%);
    color: white;
}

.btn-success:hover {
    opacity: 0.9;
}

.btn-danger {
    background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: #dfe6e9;
    color: #2d3436;
}

.btn-secondary:hover {
    background: #b2bec3;
}

.btn-block {
    width: 100%;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    min-height: 56px;
}

/* ===== Upload Zone ===== */
.upload-zone {
    border: 2px dashed #b2bec3;
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    background: #fafafa;
    transition: all 0.3s;
    cursor: pointer;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.upload-zone.dragover {
    border-color: #667eea;
    background: rgba(102,126,234,0.05);
}

.upload-zone .icon {
    font-size: 3rem;
    opacity: 0.5;
}

.upload-zone .hint {
    color: #636e72;
    font-size: 0.9rem;
}

.upload-preview {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    margin-top: 1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #dfe6e9;
}

th {
    font-weight: 600;
    color: #636e72;
    background: #f8f9fa;
    white-space: nowrap;
}

tr:hover {
    background: #f8f9fa;
}

/* ===== Status Badges ===== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-pending {
    background: #fff3cd;
    color: #856404;
}

.badge-approved {
    background: #d4edda;
    color: #155724;
}

.badge-rejected {
    background: #f8d7da;
    color: #721c24;
}

/* ===== Login Page ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    text-align: center;
    color: #636e72;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-footer {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #636e72;
}

.login-footer a {
    color: #667eea;
    text-decoration: none;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

.alert-success {
    background: #efe;
    color: #2a5;
    border: 1px solid #cfc;
}

/* ===== Review Image ===== */
.review-image {
    max-width: 100%;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* ===== OCR Result Preview ===== */
.ocr-preview {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 1rem;
    font-family: monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
}

/* ===== Period Tabs ===== */
.period-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.period-tab {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    color: #636e72;
    background: white;
    font-size: 0.9rem;
    transition: all 0.2s;
    border: 1px solid #dfe6e9;
}

.period-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

/* ===== Data Cards for Admin ===== */
.data-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.data-field {
    flex: 1;
    min-width: 120px;
}

.data-field label {
    font-size: 0.75rem;
    color: #636e72;
    display: block;
    margin-bottom: 0.2rem;
}

.data-field input {
    width: 100%;
    padding: 0.5rem;
    border: 1.5px solid #dfe6e9;
    border-radius: 8px;
    font-size: 1rem;
}

/* ===== Mobile Responsive ===== */
/* ===== Safe Area (notch phones) ===== */
body {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.navbar {
    padding-top: env(safe-area-inset-top, 0);
}

@media (max-width: 768px) {
    .nav-menu {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        flex-direction: column;
        padding: 0.5rem;
        gap: 0;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        max-height: calc(100vh - 56px);
        overflow-y: auto;
    }

    .nav-menu.active {
        display: flex;
    }

    .nav-link {
        padding: 0.75rem 1rem;
        width: 100%;
        border-radius: 6px;
    }

    .nav-toggle {
        display: block;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem 0.75rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .main-content {
        padding: 0.75rem;
    }

    .card {
        padding: 1rem;
        border-radius: 10px;
    }

    .card-title {
        font-size: 1rem;
    }

    .upload-zone {
        padding: 1.5rem 1rem;
        min-height: 150px;
    }

    .upload-zone .icon {
        font-size: 2.5rem;
    }

    .upload-zone .hint {
        font-size: 0.8rem;
    }

    .upload-preview {
        max-height: 300px;
    }

    th, td {
        padding: 0.6rem 0.4rem;
        font-size: 0.8rem;
    }

    th {
        font-size: 0.75rem;
    }

    .login-box {
        padding: 1.5rem;
        border-radius: 16px;
    }

    .login-title {
        font-size: 1.3rem;
    }

    .data-row {
        gap: 0.5rem;
    }

    .data-field {
        min-width: 100px;
    }

    .btn {
        min-height: 44px;
        font-size: 0.95rem;
        padding: 0.6rem 1rem;
    }

    .btn-large {
        min-height: 50px;
        font-size: 1rem;
    }

    .period-tabs {
        gap: 0.4rem;
    }

    .period-tab {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Loading spinner for mobile */
    @keyframes spin {
        to { transform: rotate(360deg); }
    }

    .loading-spinner {
        display: inline-block;
        width: 40px;
        height: 40px;
        border: 3px solid rgba(102,126,234,0.2);
        border-top-color: #667eea;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }
}

/* ===== Touch device optimizations ===== */
@media (hover: none) and (pointer: coarse) {
    .btn, .nav-link, .period-tab, .upload-zone {
        -webkit-tap-highlight-color: transparent;
    }

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

    .stat-card:active {
        transform: scale(0.97);
    }
}

@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}
