﻿/* ============================================================
   site.css - loaded on EVERY page.

   Only genuinely app-wide rules belong here: reset, layout, header,
   sidebar, and the shared controls that more than one page uses.

   Page-specific selectors go in /css/<page>.css. The reason is cost:
   every visitor downloads and parses this file on every navigation, so
   anything parked here is paid for app-wide forever, and nobody can
   later prove which page still needs a given rule.

   The consolidated blocks below (.form-*, .btn-*, .empty-state,
   .loading-spinner, .date-*) were each duplicated across 3-5 separate
   page templates in the old SPA, where they all landed in one cascade
   and the last-loaded page won. They are defined once here now.
   ============================================================ */

/* ---------- reset ---------- */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

/* ---------- header ---------- */

.header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 12px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-toggle {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.menu-toggle:hover {
    background-color: rgba(255,255,255,0.2);
}

.header-title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.main-title {
    font-size: 18px;
    font-weight: 600;
}

.sub-title {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 300;
}

/* ---------- sidebar ---------- */

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: white;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 1100;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.sidebar.active {
    left: 0;
}

.menu-toggle2 {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
    z-index: 10;
}

.menu-toggle2:hover {
    background: rgba(255,255,255,0.2);
}

.sidebar-header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 10px 20px;
    text-align: center;
    position: relative;
    padding-left: 60px;
}

.sidebar-header h2 {
    font-size: 16px;
    margin-bottom: 5px;
}

.sidebar-header p {
    font-size: 12px;
    opacity: 0.9;
}

.sidebar-menu {
    padding: 20px 0;
}

.menu-section {
    margin-bottom: 10px;
}

.menu-section-title {
    padding: 12px 20px 8px 20px;
    font-size: 11px;
    font-weight: 700;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #f7fafc 0%, #edf2f7 100%);
    position: relative;
}

.menu-section-title::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 20px;
    width: 30px;
    height: 2px;
    background: #2a5298;
}

.menu-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 8px 20px;
    color: #333;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    cursor: pointer;
}

.menu-item:hover {
    background-color: #f8f9fa;
    border-left-color: #2a5298;
}

.menu-item.active {
    background-color: #e3f2fd;
    border-left-color: #2a5298;
    color: #1976d2;
    font-weight: 500;
}

.menu-item-en {
    font-size: 14px;
}

.menu-item-cn {
    font-size: 12px;
    opacity: 0.7;
    white-space: nowrap;
}

.menu-separator {
    border-top: 1px solid #eee;
    margin: 10px 0;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ---------- layout ---------- */

.main-content {
    margin-top: 60px;
    padding: 20px;
    min-height: calc(100vh - 60px);
}

/* In the old SPA .page was toggled with .active because every page lived in
   one document. One page per document now, so it is simply the content card. */
.page {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    padding: 20px;
    margin-bottom: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.page-title {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e3f2fd;
}

.page-title-en {
    font-size: 24px;
    font-weight: 600;
    color: #1976d2;
    margin-bottom: 5px;
}

.page-title-cn {
    font-size: 16px;
    color: #666;
    font-weight: 400;
}

/* ---------- buttons ---------- */

.btn {
    display: inline-block;
    padding: 10px 20px;
    background: #2a5298;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s;
    margin: 5px;
}

.btn:hover      { background: #1e3c72; transform: translateY(-1px); }
.btn:disabled   { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary    { background: #2a5298; }
.btn-secondary  { background: #6c757d; }
.btn-secondary:hover { background: #545b62; }
.btn-success    { background: #28a745; }
.btn-success:hover   { background: #218838; }
.btn-danger     { background: #dc3545; }
.btn-danger:hover    { background: #c82333; }
.btn-small      { padding: 8px 15px; font-size: 12px; }
.btn-block      { display: block; width: 100%; margin: 5px 0; }

/* consolidated: these were repeated in 3-5 templates each */
.btn-save   { background: #28a745; }
.btn-save:hover   { background: #218838; }
.btn-cancel { background: #6c757d; }
.btn-cancel:hover { background: #545b62; }

.btn-back, .back-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #eef2f7;
    color: #2a5298;
    border: 1px solid #d6e0ec;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 15px;
}

.btn-back:hover, .back-button:hover {
    background: #e3ecf7;
    border-color: #2a5298;
}

/* ---------- forms ---------- */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px; /* 16px stops iOS Safari zooming the page on focus */
    transition: border-color 0.2s;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: #2a5298;
    box-shadow: 0 0 0 2px rgba(42, 82, 152, 0.1);
}

.form-control:disabled {
    background: #f1f3f5;
    color: #868e96;
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.form-hint {
    font-size: 12px;
    color: #777;
    margin-top: 4px;
}

.form-error {
    font-size: 13px;
    color: #a94442;
    margin-top: 4px;
}

/* ---------- date navigation (was duplicated in 3 templates) ---------- */

.date-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.date-nav-btn {
    padding: 8px 14px;
    background: #2a5298;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

.date-nav-btn:hover { background: #1e3c72; }

.date-input {
    padding: 9px 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 16px;
    background: white;
}

.date-input:focus {
    outline: none;
    border-color: #2a5298;
}

.btn-today {
    padding: 8px 14px;
    background: #17a2b8;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
}

.btn-today:hover { background: #138496; }

/* ---------- notices ----------
   Shared: change-password (reset warning), user-edit (editing yourself),
   attendance-edit (values carried over from the previous period). These lived in
   personal.css until a third page needed them — and user-edit, which never loaded
   that file, had been rendering its notice unstyled. */

.notice {
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 18px;
    font-size: 14px;
}

.notice .cn { display: block; margin-top: 4px; font-size: 13px; opacity: 0.85; }

.notice-warn { background: #fff3cd; border: 1px solid #ffe08a; color: #7a5b00; }
.notice-info { background: #e3f2fd; border: 1px solid #bbdefb; color: #0d47a1; }

/* ---------- state blocks (were duplicated in 4 templates) ---------- */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #888;
}

.empty-icon {
    font-size: 42px;
    margin-bottom: 10px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    color: #666;
    margin-bottom: 5px;
}

.loading-spinner {
    display: block;
    width: 34px;
    height: 34px;
    margin: 30px auto;
    border: 4px solid #e3f2fd;
    border-top-color: #2a5298;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.error-state {
    text-align: center;
    padding: 30px 20px;
    color: #a94442;
}

/* ---------- error page ---------- */

.page-error .error-box {
    max-width: 460px;
    margin: 40px auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    padding: 32px 24px;
    text-align: center;
}

.page-error .error-code {
    font-size: 56px;
    font-weight: 700;
    color: #2a5298;
    line-height: 1;
}

.page-error .error-heading {
    font-size: 20px;
    font-weight: 600;
    margin: 10px 0 6px;
}

.page-error .error-detail {
    color: #666;
    margin-bottom: 20px;
    word-break: break-word;
}

/* ---------- toasts / dialog / loading overlay ---------- */

.sp-message-container {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 300px;
    max-width: 500px;
    padding: 15px 20px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s ease-in-out;
}

.sp-message-show    { top: 80px; opacity: 1; }
.sp-message-success { background-color: #dff0d8; border: 1px solid #d6e9c6; color: #3c763d; }
.sp-message-error   { background-color: #f2dede; border: 1px solid #ebccd1; color: #a94442; }
.sp-message-title   { font-weight: bold; margin-bottom: 5px; font-size: 16px; color: inherit; }
.sp-message-text    { font-size: 14px; color: inherit; }

.sp-dialog-container {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 300px;
    max-width: 500px;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 99999;
    opacity: 0;
    transition: all 0.3s ease-in-out;
    background-color: #eef6fa;
    border: 1px solid #b3cde0;
}

.sp-dialog-show    { top: 80px; opacity: 1; }
.sp-dialog-title   { font-weight: bold; margin-bottom: 10px; font-size: 16px; color: #035b96; }
.sp-dialog-text    { font-size: 14px; margin-bottom: 15px; color: #033e66; }
.sp-dialog-buttons { display: flex; justify-content: flex-end; gap: 10px; }

.sp-dialog-button {
    padding: 6px 16px;
    border-radius: 3px;
    border: none;
    cursor: pointer;
    font-size: 14px;
}

.sp-dialog-yes      { background-color: #cce5ff; border: 1px solid #b3cde0; color: #004085; }
.sp-dialog-yes:hover{ background-color: #b3d7ff; }
.sp-dialog-no       { background-color: #e6f3ff; border: 1px solid #cce5ff; color: #033e66; }
.sp-dialog-no:hover { background-color: #cce5ff; }

#bigLoadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

#loadingSpinner {
    width: 120px;
    height: 120px;
    border: 10px solid #fff;
    border-top: 10px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ---------- responsive ---------- */

@media (max-width: 768px) {
    .header       { padding: 10px 15px; }
    .main-title   { font-size: 16px; }
    .sub-title    { font-size: 12px; }
    .main-content { padding: 15px; }
    .page         { padding: 15px; }
    .page-title-en{ font-size: 20px; }
    .page-title-cn{ font-size: 14px; }
}

@media (max-width: 480px) {
    .sidebar      { width: 100%; left: -100%; }
    .main-content { padding: 10px; }
    .page         { padding: 15px; margin-bottom: 15px; }
    .form-actions .btn { flex: 1 1 auto; }
}
