/* ============================================================
   ระบบจัดการพนักงาน - Stylesheet หลัก
   แนวคิดการออกแบบ: "กระดานสั่งงานในครัว" - อบอุ่น ชัดเจน อ่านง่าย
   เน้นใช้งานบนมือถือเป็นหลัก เพราะพนักงานหน้าร้านใช้มือถือ
   ============================================================ */

:root {
    /* Palette: ได้แรงบันดาลใจจากกระดานไม้ในครัว + กระดาษใบเสร็จ */
    --charcoal: #2b2420;       /* ไม้เผาเข้ม - ข้อความหลัก */
    --paper: #faf6ee;          /* กระดาษครีม - พื้นหลัง */
    --paper-white: #fffdf8;    /* การ์ด/พื้นผิว */
    --terracotta: #c15a3e;     /* สีหลัก - ปุ่ม/accent */
    --terracotta-dark: #a3492f;
    --sage: #6b8068;           /* สีรอง - สถานะสำเร็จ */
    --mustard: #d99a3d;        /* สีเตือน/รออนุมัติ */
    --rust-red: #b8453a;       /* สีผิดพลาด/แจ้งเตือน */
    --line: #e3d9c8;           /* เส้นแบ่ง */
    --muted: #8a7e6e;          /* ข้อความรอง */

    --font-display: 'Sukhumvit Set', 'Kanit', 'Noto Sans Thai', sans-serif;
    --font-body: 'Noto Sans Thai', 'Sukhumvit Set', sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;

    --radius: 10px;
    --shadow-card: 0 1px 3px rgba(43, 36, 32, 0.08), 0 1px 2px rgba(43, 36, 32, 0.06);
    --shadow-lift: 0 4px 14px rgba(43, 36, 32, 0.12);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--charcoal);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; margin: 0 0 8px; }

a { color: var(--terracotta); text-decoration: none; }

/* ===================== Login / Setup Pages ===================== */
.login-body {
    background: linear-gradient(160deg, #f1e9d8 0%, var(--paper) 60%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-container { width: 100%; max-width: 400px; }
.login-card {
    background: var(--paper-white);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 36px 32px;
    box-shadow: var(--shadow-lift);
}
.login-title { font-size: 22px; text-align: center; color: var(--terracotta-dark); }
.login-subtitle { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.login-form .form-group { margin-bottom: 16px; }

/* ===================== Form elements ===================== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 13.5px;
    margin-bottom: 6px;
    color: var(--charcoal);
}
.form-group .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], input[type="file"],
select, textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--line);
    border-radius: 8px;
    font-size: 15px;
    font-family: var(--font-body);
    background: var(--paper-white);
    color: var(--charcoal);
    transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--terracotta);
    box-shadow: 0 0 0 3px rgba(193, 90, 62, 0.12);
}
textarea { min-height: 80px; resize: vertical; }

/* ===================== Buttons ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14.5px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--terracotta); color: #fff; }
.btn-primary:hover { background: var(--terracotta-dark); }
.btn-secondary { background: var(--sage); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--line); color: var(--charcoal); }
.btn-outline:hover { border-color: var(--terracotta); color: var(--terracotta); }
.btn-danger { background: var(--rust-red); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===================== App Shell ===================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--charcoal);
    color: #e8e0d4;
    flex-shrink: 0;
    padding: 20px 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.25s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 12px;
}
.sidebar-brand-icon { font-size: 24px; }
.sidebar-brand-text { font-family: var(--font-display); font-weight: 700; font-size: 16px; color: #fff; }

.sidebar-menu { list-style: none; margin: 0; padding: 0; }
.sidebar-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #9a8d78;
    padding: 16px 20px 6px;
}
.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 20px;
    color: #d8cfc0;
    font-size: 14.5px;
    border-left: 3px solid transparent;
}
.sidebar-menu li a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-menu li a.active {
    background: rgba(193, 90, 62, 0.18);
    border-left-color: var(--terracotta);
    color: #fff;
    font-weight: 600;
}
.menu-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

.app-main {
    flex: 1;
    margin-left: 250px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--paper-white);
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--charcoal);
}
.page-title { flex: 1; font-size: 18px; margin: 0; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role-badge {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 20px;
    font-weight: 600;
}
.badge-admin { background: rgba(193,90,62,0.15); color: var(--terracotta-dark); }
.badge-employee { background: rgba(107,128,104,0.15); color: var(--sage); }

.content-area { flex: 1; padding: 24px; max-width: 1200px; width: 100%; }

/* ===================== Cards / Tables ===================== */
.card {
    background: var(--paper-white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px;
    margin-bottom: 20px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.card-header h3 { font-size: 16px; margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f3ecdd; font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
tbody tr:hover { background: #fbf7ee; }
td.wrap { white-space: normal; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.total-row td { font-weight: 700; background: #f3ecdd; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 10px; }

/* ===================== Stat cards (dashboard) ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--paper-white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-card);
}
.stat-card.stat-card-link {
    display: block;
    color: var(--charcoal);
    text-decoration: none;
    transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
    cursor: pointer;
}
.stat-card.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lift);
    border-color: var(--terracotta);
}
.stat-card.stat-card-link:active { transform: translateY(0); }
.stat-card .stat-icon { font-size: 22px; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; font-family: var(--font-display); }
.stat-card .stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ===================== Badges ===================== */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-orange { background: rgba(217,154,61,0.18); color: #8a5e1c; }
.badge-green { background: rgba(107,128,104,0.18); color: #4a5d47; }
.badge-red { background: rgba(184,69,58,0.15); color: var(--rust-red); }
.badge-gray { background: #e9e3d6; color: var(--muted); }
.badge-blue { background: rgba(91,124,153,0.15); color: #3f607a; }

/* ===================== Alerts ===================== */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fbeae7; color: var(--rust-red); border: 1px solid #f1c5be; }
.alert-success { background: #ecf2ea; color: #4a5d47; border: 1px solid #cfe0cb; }

/* ===================== Month/Year filter ===================== */
.month-filter { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.month-filter select { width: auto; }

/* ===================== Action buttons in tables ===================== */
.action-group { display: flex; gap: 6px; }

/* ===================== Product catalog grid ===================== */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.product-card {
    background: var(--paper-white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
}
.product-card-image {
    width: 100%;
    height: 140px;
    background: #f3ecdd;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.product-card-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-card-image .placeholder-icon { font-size: 38px; opacity: 0.35; }
.product-card-body {
    padding: 14px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.product-card-name { font-weight: 700; font-size: 15px; line-height: 1.3; }
.product-card-meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.product-card-price { font-size: 18px; font-weight: 700; color: var(--terracotta-dark); font-family: var(--font-display); }
.product-card-note { font-size: 13px; color: var(--charcoal); opacity: 0.85; }
.product-card-actions {
    display: flex;
    gap: 6px;
    margin-top: auto;
    padding-top: 10px;
    flex-wrap: wrap;
}

/* ===================== Responsive ===================== */
@media (max-width: 880px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .app-main { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .content-area { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .user-name { display: none; }
    .btn-change-password .btn-label { display: none; }
    table { font-size: 13px; }
    th, td { padding: 8px; }
}

@media (max-width: 480px) {
    .login-card { padding: 28px 22px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===================== Reduced motion ===================== */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ===================== Print styles ===================== */
@media print {
    .sidebar, .topbar, .sidebar-overlay, .sidebar-toggle,
    .btn, .action-group, .month-filter, .confirm-delete,
    form:not(.print-include), .stat-card-link, .stats-grid,
    #payModal, #reviewModal { display: none !important; }

    body { background: white; }
    .app-main { margin-left: 0 !important; }
    .content-area { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; page-break-inside: avoid; }
    .table-wrap { overflow: visible !important; }
    table { width: 100% !important; font-size: 12px !important; }
    th, td { padding: 6px 8px !important; }
    .print-header { display: block !important; margin-bottom: 20px !important; }
    .print-header h2 { font-size: 28px !important; margin: 0 0 6px !important; }
    .print-header p { font-size: 14px !important; }
    .no-print { display: none !important; }
    a { color: inherit !important; text-decoration: none !important; }
}

.print-header { display: none; }
.print-btn { cursor: pointer; }
