:root {
    --navy: #102a43;
    --blue: #1676d2;
    --bg: #f3f7fb;
    --line: #dce5ef;
    --text: #243b53;
    --sidebar-width: 300px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Tahoma, "Noto Sans Thai", sans-serif;
    font-size: 14px;
}

.topbar {
    height: 70px;
    background: var(--navy);
    display: flex;
    align-items: center;
    padding: 0 24px;
    color: #fff;
    position: fixed;
    inset: 0 0 auto;
    z-index: 20;
}

.logo {
    height: 62px;
    width: 92px;
    object-fit: contain;
    margin-right: 16px;
}

.system-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: .4px;
}

.user-panel {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 13px;
}

.company-switcher {
    min-width: 180px;
    background: #183b5b;
    color: #fff;
    border-color: #6d8aaa;
}

.user-panel small {
    display: block;
    color: #c7d8ea;
    margin-top: 2px;
}

.bell {
    color: #72c7ff;
}

.logout,
.outline {
    border: 1px solid #a8c4dd;
    background: transparent;
    color: inherit;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.sidebar {
    position: fixed;
    top: 70px;
    bottom: 0;
    width: var(--sidebar-width);
    background: #fff;
    border-right: 1px solid var(--line);
    overflow-y: auto;
    z-index: 10;
    padding: 14px 10px;
}

.sidebar-backdrop {
    display: none;
}

.nav-item {
    width: 100%;
    border: 0;
    background: none;
    text-align: left;
    padding: 12px 14px;
    display: flex;
    gap: 12px;
    align-items: center;
    color: #486581;
    text-decoration: none;
    border-radius: 7px;
    font: inherit;
    cursor: pointer;
}

.nav-item b {
    margin-left: auto;
}

.nav-item:hover,
.nav-item.active,
.nav-item.open {
    background: #e7f2fd;
    color: #1167b1;
    font-weight: bold;
}

.sub-menu {
    display: none;
    padding: 2px 0 8px 34px;
}

.sub-menu.show {
    display: block;
}

.sub-menu a {
    display: block;
    padding: 8px 0;
    color: #627d98;
    text-decoration: none;
    line-height: 1.35;
}

.sub-menu-heading {
    display: block;
    margin: 10px 0 4px;
    padding-top: 8px;
    border-top: 1px solid #edf2f7;
    color: #102a43;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.sub-menu a:hover,
.sub-menu a.active {
    color: var(--blue);
    font-weight: bold;
}

.content {
    margin: 70px 0 0 var(--sidebar-width);
    padding: 28px;
    min-height: calc(100vh - 70px);
}

.page-banner {
    background: linear-gradient(120deg, #153e64, #1979bc);
    min-height: 118px;
    border-radius: 12px;
    padding: 24px 28px;
    display: flex;
    justify-content: space-between;
    color: #fff;
    align-items: center;
    margin-bottom: 22px;
}

.page-banner h1 {
    margin: 4px 0;
    font-size: 27px;
}

.breadcrumb {
    margin: 0;
    color: #c3e2f8;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stats article,
.panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 2px 7px #102a4308;
}

.stats article {
    padding: 18px;
    border-left: 4px solid var(--blue);
}

.stats span,
.stats small {
    display: block;
    color: #627d98;
}

.stats strong {
    display: block;
    font-size: 30px;
    margin: 6px 0;
    color: var(--navy);
}

.panel {
    padding: 20px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.panel h2 {
    margin: 0;
    font-size: 18px;
}

.outline {
    color: var(--blue);
    border-color: #8ec4f4;
}

.empty,
.empty-state {
    text-align: center;
    padding: 55px;
    color: #627d98;
}

.empty-state h3 {
    color: var(--navy);
}

.inline-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    background: #f7fafc;
    padding: 42px 14px 14px;
    border: 1px solid #d9e6f2;
    border-left: 4px solid var(--blue);
    border-radius: 10px;
    margin-bottom: 22px;
    position: relative;
}

.inline-form::before {
    content: "1. กรอกข้อมูลตามลำดับ";
    position: absolute;
    top: 12px;
    left: 14px;
    color: var(--navy);
    font-weight: 700;
    font-size: 13px;
}

.inline-form .primary {
    grid-column: 1 / -1;
    justify-self: start;
    min-width: 150px;
    margin-top: 4px;
}

.form-section {
    grid-column: 1 / -1;
    border-top: 1px solid #d9e6f2;
    padding-top: 12px;
    color: var(--navy);
}

.form-section:first-child {
    border-top: 0;
    padding-top: 0;
}

.form-section strong {
    display: block;
    font-size: 14px;
}

.form-note {
    display: block;
    color: #5f7895;
    font-size: 12px;
    margin-top: 3px;
}

input,
select {
    padding: 9px 10px;
    border: 1px solid #bcccdc;
    border-radius: 6px;
    background: #fff;
    min-width: 135px;
    width: 100%;
    font: inherit;
}

.date-th {
    background-image: linear-gradient(transparent, transparent);
    cursor: pointer;
}

.hidden-date-picker {
    cursor: pointer;
}

.year-calendar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.month-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    background: #f8fbff;
}

.month-card h3 {
    margin: 0 0 10px;
    color: var(--navy);
}

.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-day {
    min-height: 34px;
    border: 1px solid #d7e3ef;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
}

.calendar-day small {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--blue);
    color: #fff;
    border-radius: 999px;
    padding: 1px 5px;
    font-size: 10px;
}

.news-card {
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    background: #fff;
}

.news-card.unread {
    background: #fff8e6;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.setting-card,
.check-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
}

.approval-form {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.primary {
    border: 0;
    background: var(--blue);
    color: #fff;
    border-radius: 6px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: bold;
}

.danger {
    border: 0;
    background: #dc2626;
    color: #fff;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: bold;
}

.danger:hover {
    background: #b91c1c;
}

.action-link {
    display: inline-block;
    margin: 0 6px 6px 0;
    text-decoration: none;
    color: var(--blue);
}

td form {
    display: inline-block;
}

.table-wrap {
    overflow-x: auto;
    border-top: 1px solid var(--line);
    padding-top: 14px;
    position: relative;
}

.table-wrap::before {
    content: "2. รายการข้อมูล";
    display: inline-block;
    margin-bottom: 10px;
    color: var(--navy);
    font-weight: 700;
    font-size: 13px;
}

button,
.primary,
.danger,
.outline,
.logout {
    transition: background .15s ease, border-color .15s ease, transform .05s ease;
}

button:active,
.primary:active,
.danger:active,
.outline:active,
.logout:active {
    transform: translateY(1px);
}

table {
    border-collapse: collapse;
    width: 100%;
    min-width: 620px;
}

th,
td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
}

th {
    color: #486581;
    font-size: 12px;
    text-transform: uppercase;
}

.status {
    background: #e3f9e5;
    color: #237804;
    border-radius: 20px;
    padding: 4px 9px;
    font-size: 12px;
}

.no-data {
    text-align: center;
    color: #829ab1;
}

.alert {
    background: #e3f9e5;
    color: #237804;
    padding: 12px 16px;
    border-radius: 7px;
    margin-bottom: 16px;
}

.hamburger {
    display: none;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #102a43, #1976b9);
}

.login-card {
    background: #fff;
    width: min(420px, calc(100% - 32px));
    padding: 38px;
    border-radius: 14px;
    box-shadow: 0 25px 70px #0004;
    text-align: center;
}

.login-logo {
    height: 72px;
    width: 72px;
    object-fit: contain;
}

.login-card h1 {
    font-size: 22px;
    color: var(--navy);
    margin: 8px 0;
}

.login-card p {
    color: #627d98;
}

.login-card form {
    text-align: left;
    margin: 24px 0;
}

.login-card label {
    display: block;
    margin: 14px 0;
    color: #486581;
}

.login-card input:not([type=checkbox]) {
    width: 100%;
    display: block;
    margin-top: 6px;
}

.remember {
    font-size: 13px;
}

.login-card .primary {
    width: 100%;
    margin-top: 10px;
}

.error {
    color: #c53030 !important;
    font-size: 13px;
}

.print-body {
    background: #eef3f8;
    color: #111827;
}

.print-toolbar {
    max-width: 210mm;
    margin: 16px auto;
    display: flex;
    gap: 8px;
}

.a4-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 24px;
    background: #fff;
    padding: 16mm;
    box-shadow: 0 12px 40px #102a4326;
}

.print-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 2px solid #102a43;
    padding-bottom: 12px;
    margin-bottom: 14px;
}

.print-header h1 {
    margin: 0 0 6px;
    font-size: 24px;
}

.print-header p {
    margin: 0;
    color: #486581;
}

.print-doc-no {
    text-align: right;
}

.print-doc-no strong,
.print-doc-no span {
    display: block;
}

.print-section {
    border: 1px solid #d7e3ef;
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
}

.print-section h2 {
    margin: 0 0 10px;
    font-size: 16px;
    color: #102a43;
}

.print-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 18px;
}

.print-grid p,
.print-section p {
    margin: 4px 0;
}

.print-table {
    min-width: 0;
    width: 100%;
}

.print-table th,
.print-table td {
    border: 1px solid #d7e3ef;
    padding: 8px;
    vertical-align: top;
}

.print-signatures {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20mm;
    margin-top: 24mm;
    text-align: center;
}

.signature-form {
    display: grid;
    gap: 10px;
}

#signature-pad {
    width: 100%;
    max-width: 100%;
    height: 220px;
    border: 1px dashed #829ab1;
    border-radius: 8px;
    background: #fff;
    touch-action: none;
}

.signature-actions {
    display: flex;
    gap: 8px;
}

.signature-image {
    width: 100%;
    max-width: 360px;
    height: auto;
    border: 1px solid #d7e3ef;
    border-radius: 8px;
}

.print-only {
    display: none;
}

@media print {
    @page {
        size: A4;
        margin: 10mm;
    }

    body,
    .print-body {
        background: #fff;
    }

    .no-print {
        display: none !important;
    }

    .print-only {
        display: block;
    }

    .a4-page {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .print-section {
        break-inside: avoid;
    }
}

@media(max-width:850px) {
    :root {
        --sidebar-width: min(86vw, 340px);
    }

    .system-name {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 18px 0 40px #102a4333;
        z-index: 35;
        padding-bottom: 28px;
    }

    .sidebar-open .sidebar {
        transform: none;
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 70px 0 0 0;
        background: rgba(16, 42, 67, .38);
        z-index: 30;
    }

    .content {
        margin-left: 0;
        padding: 16px;
        padding-bottom: 28px;
    }

    .hamburger {
        display: block;
        background: #183b5b;
        color: #fff;
        border: 0;
        font-size: 24px;
        margin-right: 10px;
        border-radius: 8px;
        width: 42px;
        height: 42px;
        line-height: 42px;
    }

    .topbar {
        padding: 0 14px;
        gap: 8px;
    }

    .logo {
        height: 50px;
        width: 72px;
        margin-right: 6px;
    }

    .company-switcher {
        min-width: 130px;
        max-width: 38vw;
    }

    .user-panel {
        gap: 8px;
        min-width: 0;
    }

    .user-panel strong,
    .user-panel small,
    .logout {
        display: none;
    }

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

    .page-banner {
        padding: 18px;
        min-height: 96px;
        align-items: flex-start;
    }

    .page-banner span {
        display: none;
    }

    .inline-form {
        grid-template-columns: 1fr;
    }

    .panel-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .settings-grid,
    .year-calendar {
        grid-template-columns: 1fr;
    }
}

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

    .page-banner h1 {
        font-size: 23px;
    }

    .content {
        padding: 12px;
    }

    .panel {
        padding: 14px;
    }

    .inline-form>* {
        width: 100%;
    }

    .system-name {
        max-width: 120px;
    }

    .company-switcher {
        display: none;
    }

    .topbar {
        height: 64px;
    }

    .sidebar {
        top: 64px;
    }

    .sidebar-open .sidebar-backdrop {
        inset: 64px 0 0 0;
    }

    .content {
        margin-top: 64px;
    }
}
