@font-face {
    font-family: 'THSarabunNew';
    src: url('/static/fonts/THSarabunNew.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'THSarabunNew';
    src: url('/static/fonts/THSarabunNew-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}
@font-face {
    font-family: 'THSarabunPSK';
    src: url('/static/fonts/THSarabun.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'THSarabunPSK';
    src: url('/static/fonts/THSarabun-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

:root {
    --primary: #1e3a8a;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --accent: #0284c7;
    --stamp-blue: #003399;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: 265px;
    background: linear-gradient(180deg, #0f172a 0%, #1e3a8a 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    z-index: 20;
}

.brand {
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #fbbf24;
    color: #1e3a8a;
    font-weight: 800;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.brand-text h1 {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
}

.brand-text p {
    font-size: 12px;
    color: #93c5fd;
    margin-top: 2px;
}

.nav-menu {
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.nav-btn {
    background: transparent;
    color: #cbd5e1;
    border: none;
    text-align: left;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.15s ease;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.nav-btn.active {
    background: #2563eb;
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.nav-btn .badge {
    margin-left: auto;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 99px;
    font-weight: 700;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.12);
    font-size: 12px;
    color: #94a3b8;
}

/* Main Content */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 62px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.content-area {
    padding: 20px 24px;
    flex: 1;
    overflow-y: auto;
}

.view-section {
    display: none;
}

.view-section.active {
    display: block;
}

/* Cards & Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--primary);
    margin-top: 4px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Buttons & Inputs */
.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    text-decoration: none;
}

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

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    background: #047857;
}

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

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

.btn-outline {
    background: #fff;
    border-color: #cbd5e1;
    color: #334155;
}
.btn-outline:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12.5px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
}

/* Sub-tabs */
.tabs-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    flex-wrap: wrap;
}

.tab-pill {
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f8fafc;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

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

/* Tables */
.table-wrap {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

table.data-table th {
    background: #f8fafc;
    color: #334155;
    font-weight: 700;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

table.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table-input {
    width: 100%;
    padding: 6px 9px;
    font-size: 13.5px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    color: #0f172a;
    box-sizing: border-box;
    transition: all 0.15s ease;
}
.table-input:focus {
    border-color: #2563eb;
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
    background: #f8fafc;
}
.table-select {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    color: #0f172a;
    box-sizing: border-box;
}
.table-select:focus {
    border-color: #2563eb;
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

table.data-table tr:hover td {
    background: #f8fafc;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}
.status-new { background: #fee2e2; color: #b91c1c; }
.status-received { background: #dbeafe; color: #1d4ed8; }
.status-stamped { background: #fef3c7; color: #b45309; }
.status-assigned { background: #d1fae5; color: #047857; }

.tag-chip {
    display: inline-block;
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 11.5px;
    margin: 2px 3px 2px 0;
}

/* Stamp Studio Layout */
.studio-layout {
    display: grid;
    grid-template-columns: minmax(480px, 1.35fr) minmax(380px, 1fr);
    gap: 20px;
    align-items: start;
}

@media (max-width: 1150px) {
    .studio-layout {
        grid-template-columns: 1fr;
    }
}

.pdf-stage-card {
    background: #334155;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: sticky;
    top: 12px;
}

.pdf-toolbar {
    width: 100%;
    background: #1e293b;
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 13px;
}

.pdf-canvas-container {
    position: relative;
    background: #fff;
    box-shadow: 0 8px 30px rgba(0,0,0,0.45);
    user-select: none;
    overflow: hidden;
    max-width: 100%;
}

.pdf-bg-img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

/* Interactive Stamp Overlays on the PDF Page */
.stamp-overlay {
    position: absolute;
    cursor: move;
    box-sizing: border-box;
    border: 1.5px dashed transparent;
    transition: box-shadow 0.1s;
}

.stamp-overlay:hover,
.stamp-overlay.selected {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.55);
}

.stamp-overlay canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.resize-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    right: -6px;
    bottom: -6px;
    background: #2563eb;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    z-index: 5;
}

.stamp-badge-label {
    position: absolute;
    top: -20px;
    left: 0;
    background: #1e3a8a;
    color: #fff;
    font-size: 10.5px;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0.9;
}

/* Checkboxes list */
.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
    gap: 6px;
    max-height: 175px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}
.check-item:hover {
    background: #e2e8f0;
}

/* Calendar Grid */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.cal-day-header {
    background: #1e3a8a;
    color: #fff;
    text-align: center;
    padding: 8px 4px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 700;
}

.cal-cell {
    min-height: 98px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cal-cell.other-month {
    background: #f8fafc;
    opacity: 0.55;
}

.cal-cell.today {
    border: 2px solid #2563eb;
    background: #eff6ff;
}

.cal-date-num {
    font-size: 12.5px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 2px;
}

.cal-event-item {
    font-size: 11.5px;
    padding: 3px 6px;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}
.cal-type-deadline { background: #fee2e2; color: #991b1b; border-left: 3px solid #dc2626; }
.cal-type-meeting { background: #dbeafe; color: #1e40af; border-left: 3px solid #2563eb; }
.cal-type-training { background: #fef3c7; color: #92400e; border-left: 3px solid #d97706; }
.cal-type-other { background: #d1fae5; color: #065f46; border-left: 3px solid #059669; }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-backdrop.open {
    display: flex;
}
.modal-box {
    background: #fff;
    border-radius: 14px;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 22px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

/* Toast notification */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: #0f172a;
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
    border-left: 4px solid #38bdf8;
}
