@import url("https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css");
@import url("https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css");

:root {
    --bg: #f4f8f5;
    --bg-2: #eef4f7;
    --ink: #172027;
    --muted: #637083;
    --surface: rgba(255, 255, 255, .88);
    --surface-solid: #ffffff;
    --line: rgba(23, 32, 39, .12);
    --line-strong: rgba(23, 32, 39, .18);
    --shadow: 0 18px 48px rgba(28, 43, 54, .12);
    --shadow-soft: 0 10px 26px rgba(28, 43, 54, .08);
    --teal: #0f766e;
    --cyan: #0891b2;
    --blue: #2563eb;
    --green: #16a34a;
    --lime: #65a30d;
    --amber: #d97706;
    --coral: #e11d48;
    --violet: #7c3aed;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: Tahoma, "Noto Sans Thai", Arial, sans-serif;
    background:
        linear-gradient(140deg, rgba(15, 118, 110, .10) 0%, rgba(15, 118, 110, 0) 34%),
        linear-gradient(320deg, rgba(217, 119, 6, .10) 0%, rgba(217, 119, 6, 0) 36%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 58%, #f8f7f2 100%) !important;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(23, 32, 39, .04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(23, 32, 39, .04) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .72), transparent 72%);
    -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .72), transparent 72%);
}

.main-sidebar {
    background: #172027;
}

.brand-link {
    border-bottom-color: rgba(255, 255, 255, .08) !important;
}

.brand-image {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-left: .35rem;
    margin-right: .55rem;
    border-radius: .35rem;
    color: #f8fffb;
    background: linear-gradient(135deg, var(--teal), var(--cyan) 62%, var(--amber));
    font-weight: 900;
    line-height: 34px;
    opacity: 1 !important;
}

.nav-sidebar .nav-link.active {
    background: linear-gradient(90deg, var(--teal), var(--cyan)) !important;
    color: #fff !important;
}

.content-wrapper {
    background:
        linear-gradient(140deg, rgba(15, 118, 110, .08), rgba(15, 118, 110, 0) 36%),
        linear-gradient(320deg, rgba(217, 119, 6, .08), rgba(217, 119, 6, 0) 36%),
        #eef3f6 !important;
}

.content-header h1 {
    margin: 0;
    color: var(--ink);
    font-weight: 800;
    letter-spacing: 0;
}

.admin-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.card,
.small-box,
.info-box {
    border-radius: .55rem;
    box-shadow: 0 12px 32px rgba(23, 32, 39, .08);
}

.card {
    border: 1px solid rgba(23, 32, 39, .08);
}

.card-header {
    border-bottom-color: rgba(23, 32, 39, .08);
}

.card-title {
    font-weight: 800;
}

a {
    color: var(--teal);
    text-decoration: none;
    font-weight: 700;
}

a:hover {
    color: #0a4f4a;
}

.wrap {
    position: relative;
    max-width: 1440px !important;
    margin: 0 auto !important;
    padding: 22px !important;
}

.page-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.brand-mini,
.back-link,
.wrap > p:first-child a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #223039;
    background: rgba(255, 255, 255, .72);
    box-shadow: 0 6px 18px rgba(28, 43, 54, .06);
}

.wrap > p:first-child {
    margin: 0 0 16px;
}

.page-topbar + p,
.page-hero + p,
.page-hero + .topbar,
.topbar + p,
.page-hero + .top,
.legacy-admin-content > .page-topbar,
.legacy-admin-content > .page-hero,
.legacy-admin-content > .topbar,
.legacy-admin-content > p:first-child,
.legacy-admin-content > .panel > div:first-child[style*="display:flex"],
.legacy-ft-content > .ft-top,
.wrap > p + .panel > div:first-child[style*="display:flex"],
.page-hero + .panel > div:first-child[style*="display:flex"] {
    display: none !important;
}

.quick-actions,
.actions,
.device-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.actions,
.device-actions {
    margin-top: 16px;
}

.page-topbar .quick-actions {
    margin-top: 0;
}

.page-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    padding: 22px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 8px;
    color: #f7fffb;
    background:
        linear-gradient(115deg, rgba(18, 44, 48, .98), rgba(13, 88, 82, .96) 52%, rgba(74, 75, 43, .94));
    box-shadow: var(--shadow);
}

.page-hero h1,
.panel h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.15;
    letter-spacing: 0;
}

.page-hero .muted,
.page-hero .head-note,
.page-hero p {
    max-width: 780px;
    margin: 8px 0 0;
    color: rgba(248, 255, 251, .78) !important;
}

.panel {
    position: relative;
    margin-bottom: 16px;
    padding: 18px !important;
    border: 1px solid var(--line) !important;
    border-radius: 8px !important;
    background: var(--surface) !important;
    box-shadow: var(--shadow-soft) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.panel,
.modal,
.summary-box,
.device-picker,
.progress-panel,
.stat-card {
    color: var(--ink);
}

.panel h1,
.panel h2,
.panel h3 {
    letter-spacing: 0;
}

.panel h2 {
    font-size: 21px;
    line-height: 1.25;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    flex-wrap: wrap;
    padding-bottom: 18px;
    border-bottom-color: var(--line) !important;
}

.head-copy {
    max-width: 760px;
}

.head-note {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
}

.head-note,
.muted {
    color: var(--muted) !important;
    font-size: 13px;
    line-height: 1.55;
}

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

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

.grid,
.form-grid {
    gap: 14px !important;
}

label {
    display: block;
    color: #344252;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea,
input:not([type]) {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid rgba(99, 112, 131, .24);
    border-radius: 8px;
    color: var(--ink);
    background: rgba(255, 255, 255, .88);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72);
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(8, 145, 178, .18);
    border-color: rgba(8, 145, 178, .52);
}

button:not(.btn),
.btn:not([class*="btn-"]) {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 10px 14px !important;
    border: 1px solid transparent !important;
    border-radius: 8px !important;
    color: #ffffff !important;
    background: #17383a !important;
    font-size: 13px;
    font-weight: 900 !important;
    text-decoration: none !important;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(23, 56, 58, .16);
}

button:not(.btn):hover,
.btn:not([class*="btn-"]):hover {
    background: #0f766e !important;
}

button[disabled],
.btn[disabled] {
    opacity: .56;
    cursor: not-allowed;
}

.btn.light,
button.light,
.modal .btn.light,
.device-actions .btn.light {
    color: #17383a !important;
    border-color: var(--line) !important;
    background: rgba(255, 255, 255, .78) !important;
    box-shadow: 0 6px 16px rgba(28, 43, 54, .06);
}

.btn.secondary {
    color: #102a2c !important;
    background: #d9f99d !important;
}

.table-wrap {
    overflow: auto;
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-solid);
}

table {
    width: 100%;
    border-collapse: collapse !important;
}

.table-wrap table {
    margin-top: 0 !important;
}

th,
td {
    padding: 12px 14px !important;
    border-bottom: 1px solid rgba(23, 32, 39, .08) !important;
    text-align: left;
    vertical-align: top;
    font-size: 13px !important;
    line-height: 1.45;
}

th {
    color: var(--muted) !important;
    background: rgba(248, 250, 252, .82);
    font-size: 11px !important;
    font-weight: 900 !important;
    letter-spacing: .06em;
    text-transform: uppercase;
}

tbody tr:hover td {
    background: rgba(240, 253, 250, .62);
}

tbody tr:last-child td {
    border-bottom: 0 !important;
}

pre,
.raw-body {
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid rgba(99, 112, 131, .16) !important;
    border-radius: 8px !important;
    background: rgba(248, 250, 252, .92) !important;
}

.mono {
    font-family: "Cascadia Mono", Consolas, monospace;
}

.badge,
.pill,
.stat,
.summary-tag,
.type-badge,
.status-badge,
.badge-ok,
.badge-warn,
.tiny-flag,
.backlog-pill,
.panel-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border: 1px solid rgba(15, 118, 110, .16);
    border-radius: 999px;
    color: #155e75;
    background: #cffafe;
    font-size: 12px;
    font-weight: 900;
}

.backlog-pill {
    gap: 8px;
    margin-top: 10px;
}

.backlog-pill strong {
    font-size: 16px;
}

.stat {
    margin: 8px 8px 0 0;
    color: #17383a;
    background: rgba(217, 249, 157, .66);
}

.badge-ok,
.tiny-flag.yes,
.alert.success {
    color: #166534 !important;
    border-color: rgba(22, 163, 74, .18);
    background: #dcfce7 !important;
}

.badge-warn,
.alert.error {
    color: #92400e !important;
    border-color: rgba(217, 119, 6, .20);
    background: #fef3c7 !important;
}

.badge.ok {
    color: #166534;
    border-color: rgba(22, 163, 74, .18);
    background: #dcfce7;
}

.badge.off {
    color: #991b1b;
    border-color: rgba(225, 29, 72, .18);
    background: #fee2e2;
}

.permissions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.check {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(248, 250, 252, .82);
    font-weight: 400;
}

.check input {
    width: auto;
    min-height: 0;
    margin-top: 2px;
}

.type-attendance { color: #106947; border-color: #bee8d0; background: #e3f8ed; }
.type-device { color: #145e75; border-color: #c6e3ee; background: #e5f3f8; }
.type-heartbeat { color: #4b5563; border-color: #dde4e8; background: #f0f3f4; }
.type-oplog { color: #815000; border-color: #f2d394; background: #fff1d6; }
.type-user { color: #6d5a00; border-color: #e7da9c; background: #f7f0d2; }
.type-biodata { color: #9b2c20; border-color: #f5c4bb; background: #fde8e4; }
.type-unknown { color: #5b6672; border-color: #dce3e8; background: #eef1f3; }

.message-cell {
    min-width: 230px;
}

.raw-body {
    max-width: 620px;
    max-height: 140px;
    overflow: auto;
    margin: 0;
    padding: 10px;
}

.empty-row {
    text-align: center;
    padding: 34px !important;
}

.alert,
.flash {
    padding: 14px 16px !important;
    border: 1px solid var(--line);
    border-left: 4px solid var(--teal);
    border-radius: 8px !important;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, .86);
    box-shadow: var(--shadow-soft);
}

.summary-box,
.device-picker,
.progress-panel,
.stat-card {
    padding: 11px;
    border: 1px solid var(--line) !important;
    border-radius: 8px !important;
    background: rgba(255, 255, 255, .72) !important;
}

.summary-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    width: auto;
    height: auto;
    opacity: 1 !important;
    background: rgba(15, 23, 42, .56) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-backdrop.open {
    display: flex !important;
}

.modal-backdrop.open > .modal {
    position: relative;
    top: auto;
    left: auto;
    z-index: auto;
    display: block !important;
    width: min(760px, 100%);
    height: auto;
    max-height: 90vh;
    overflow: hidden;
    pointer-events: auto;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 8px !important;
    background: var(--surface-solid) !important;
    box-shadow: var(--shadow) !important;
}

.modal-head,
.modal-foot {
    padding: 16px 18px;
    border-color: var(--line) !important;
}

.modal-head {
    border-bottom: 1px solid var(--line);
}

.modal-foot {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    border-top: 1px solid var(--line);
}

.modal-body {
    padding: 18px;
}

.device-picker {
    max-height: 360px;
    overflow: auto;
    padding: 14px;
}

.device-picker label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    padding: 8px 0;
    font-weight: 400;
}

.device-picker input[type="checkbox"] {
    width: auto;
    min-height: 0;
    margin-top: 2px;
}

.device-picker .name {
    font-weight: 900;
}

.progress-bar {
    overflow: hidden;
    height: 10px;
    border-radius: 999px !important;
    background: rgba(23, 32, 39, .10) !important;
}

.progress-panel {
    display: none;
    margin-top: 16px;
    padding: 16px;
}

.progress-panel.open {
    display: block;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    margin-top: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), var(--cyan)) !important;
    transition: width .2s ease;
}

.stat-grid {
    gap: 10px !important;
}

.stat-card strong {
    display: block;
    font-size: 20px;
    line-height: 1.2;
    margin-top: 2px;
    color: var(--ink);
}

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 14px;
    border-top-color: var(--line) !important;
}

.pager-summary {
    font-weight: 900;
}

.pager-links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.page-link,
.page-current,
.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 8px !important;
}

.page-link {
    border: 1px solid var(--line);
    color: var(--teal);
    background: var(--surface-solid);
}

.page-current {
    border-color: #17383a !important;
    background: #17383a !important;
    color: #ffffff;
}

.login-page {
    display: grid !important;
    place-items: center !important;
    min-height: 100vh;
    padding: 22px;
}

.login-box {
    width: min(100%, 430px);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.login-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 18px;
    border-radius: 8px;
    color: #f8fffb;
    font-weight: 900;
    background: linear-gradient(135deg, var(--teal), var(--cyan) 55%, var(--amber));
}

.login-box h1 {
    margin: 0 0 8px;
    font-size: 30px;
}

@media (max-width: 900px) {
    .page-hero,
    .page-topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .quick-actions,
    .actions {
        width: 100%;
    }

    .quick-actions > *,
    .actions > * {
        flex: 1 1 180px;
    }
}

@media (max-width: 720px) {
    .wrap {
        padding: 14px !important;
    }

    .panel,
    .page-hero {
        padding: 16px !important;
    }

    .page-hero h1,
    .panel h1 {
        font-size: 26px;
    }

    button,
    .btn {
        width: 100%;
    }
}
