/* ============================================================
   Premium app UI layer
   A restrained, Apple-inspired visual system for the application.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700&display=swap');

:root {
    --ui-canvas: #f5f5f7;
    --ui-surface: #ffffff;
    --ui-surface-muted: #fbfbfd;
    --ui-ink: #1d1d1f;
    --ui-muted: #6e6e73;
    --ui-subtle: #86868b;
    --ui-line: rgba(29, 29, 31, 0.12);
    --ui-line-soft: rgba(29, 29, 31, 0.08);
    --ui-blue: #0071e3;
    --ui-blue-hover: #0077ed;
    --ui-green: #248a3d;
    --ui-red: #d70015;
    --ui-orange: #c93400;
    --ui-radius-sm: 12px;
    --ui-radius-md: 18px;
    --ui-radius-lg: 24px;
    --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 24px rgba(0, 0, 0, 0.04);
    --ui-shadow-md: 0 14px 40px rgba(0, 0, 0, 0.08);
    --ui-transition: 180ms cubic-bezier(0.2, 0.75, 0.35, 1);
}

html {
    min-height: 100%;
    background: var(--ui-canvas);
}

body.app-shell {
    min-height: 100vh;
    margin: 0;
    color: var(--ui-ink);
    background: var(--ui-canvas) !important;
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: -0.005em;
}

body.app-shell::selection {
    color: #fff;
    background: var(--ui-blue);
}

/* Navigation ------------------------------------------------- */
.app-shell .app-navbar {
    min-height: 54px;
    padding: 6px 0;
    background: rgba(255, 255, 255, 0.78);
    border-bottom: 1px solid var(--ui-line-soft);
    box-shadow: none;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.app-shell .app-navbar .container {
    max-width: 1240px;
}

.app-shell .app-navbar .navbar-brand {
    min-width: 0;
    gap: 10px;
    color: var(--ui-ink);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.app-shell .app-navbar .navbar-brand:hover,
.app-shell .app-navbar .navbar-brand:focus {
    color: var(--ui-ink);
}

.app-brand-mark {
    display: inline-grid;
    width: 30px;
    height: 30px;
    place-items: center;
    flex: 0 0 auto;
    color: #fff;
    background: #1d1d1f;
    border-radius: 9px;
    font-size: 15px;
    line-height: 1;
}

.app-brand-copy {
    display: grid;
    min-width: 0;
    line-height: 1.1;
}

.app-brand-copy small {
    overflow: hidden;
    color: var(--ui-subtle);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell .app-navbar .nav-link {
    color: var(--ui-muted);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    padding: 8px 11px !important;
}

.app-shell .app-navbar .nav-link:hover,
.app-shell .app-navbar .nav-link:focus {
    color: var(--ui-ink);
    background: rgba(0, 0, 0, 0.045);
}

.app-shell .app-navbar .app-pending-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    margin-left: 3px;
    border-radius: 999px;
    background: #ff3b30;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.app-shell .app-navbar .navbar-toggler {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--ui-line-soft);
    border-radius: 12px;
    color: var(--ui-ink);
    background: rgba(255, 255, 255, 0.74);
}

.app-shell .app-navbar .navbar-toggler:hover {
    background: #fff;
}

.app-user-menu {
    display: inline-flex !important;
    align-items: center;
    gap: 8px !important;
    min-height: 38px;
    padding: 5px 10px 5px 6px !important;
    border: 1px solid var(--ui-line-soft);
    border-radius: 999px !important;
    background: rgba(255, 255, 255, 0.76);
}

.app-user-menu:hover,
.app-user-menu:focus {
    background: #fff !important;
    border-color: var(--ui-line);
}

.app-user-avatar {
    display: inline-grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(145deg, #5f5f67, #1d1d1f);
    font-size: 14px;
}

.app-user-details {
    display: grid;
    min-width: 0;
    line-height: 1.12;
}

.app-user-name {
    overflow: hidden;
    max-width: 178px;
    color: var(--ui-ink);
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-user-role {
    overflow: hidden;
    max-width: 178px;
    color: var(--ui-subtle);
    font-size: 10px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell .dropdown-menu {
    padding: 7px;
    border: 1px solid var(--ui-line-soft) !important;
    border-radius: 16px !important;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: var(--ui-shadow-md);
    backdrop-filter: blur(18px);
}

.app-shell .dropdown-item {
    border-radius: 9px;
    color: var(--ui-ink);
    font-size: 13px;
    font-weight: 500;
}

.app-shell .dropdown-item:hover,
.app-shell .dropdown-item:focus {
    color: var(--ui-ink);
    background: #f2f2f7;
}

.app-shell .dropdown-divider {
    margin: 6px 0;
    border-color: var(--ui-line-soft);
}

/* Page composition ------------------------------------------ */
.app-shell .page-container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 46px 24px 72px;
}

.app-shell .profile-container,
.app-shell .admin-container,
.app-shell .create-user-container {
    max-width: 1240px;
    padding-top: 46px !important;
    padding-bottom: 72px !important;
}

.app-page-header,
.app-shell .page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 30px;
}

.app-page-kicker {
    margin-bottom: 5px;
    color: var(--ui-blue);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.app-shell .page-title,
.app-shell h1.page-title {
    margin: 0;
    color: var(--ui-ink);
    font-size: clamp(30px, 4vw, 42px);
    font-weight: 700;
    letter-spacing: -0.045em;
    line-height: 1.08;
}

.app-shell .page-subtitle {
    margin-top: 8px;
    color: var(--ui-muted);
    font-size: 16px;
    line-height: 1.5;
}

.app-shell h2,
.app-shell h3,
.app-shell h4,
.app-shell h5,
.app-shell h6 {
    color: var(--ui-ink);
    letter-spacing: -0.02em;
}

.app-shell .breadcrumb {
    margin-bottom: 28px;
    font-size: 13px;
}

.app-shell .breadcrumb-item,
.app-shell .breadcrumb-item.active {
    color: var(--ui-subtle);
}

.app-shell .breadcrumb-item + .breadcrumb-item::before {
    color: #b5b5ba;
}

.app-shell .breadcrumb a {
    color: var(--ui-muted);
    font-weight: 500;
}

.app-shell .breadcrumb a:hover {
    color: var(--ui-blue);
}

/* Surfaces --------------------------------------------------- */
.app-shell .app-card,
.app-shell .card,
.app-shell .tab-pane-content,
.app-shell .stat-card,
.app-shell .create-user-card {
    border: 1px solid var(--ui-line-soft) !important;
    border-radius: var(--ui-radius-md) !important;
    background: var(--ui-surface) !important;
    box-shadow: var(--ui-shadow-sm);
}

.app-shell .app-card:hover {
    box-shadow: var(--ui-shadow-sm);
}

.app-shell .app-card .card-header,
.app-shell .card > .card-header {
    padding: 17px 22px;
    border-bottom: 1px solid var(--ui-line-soft);
    background: transparent !important;
    color: var(--ui-ink);
    font-size: 16px;
    font-weight: 700;
}

.app-shell .app-card .card-body,
.app-shell .card > .card-body {
    padding: 22px;
}

.app-shell .app-card .card,
.app-shell .tab-pane-content .card {
    box-shadow: none;
}

.app-shell .card.bg-light,
.app-shell .alert-light,
.app-shell .filter-panel {
    background: var(--ui-surface-muted) !important;
}

.app-shell .card.border-danger {
    border-color: rgba(215, 0, 21, 0.3) !important;
}

.app-shell .section-title {
    color: var(--ui-subtle);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* Buttons ---------------------------------------------------- */
.app-shell .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    transition: transform var(--ui-transition), background var(--ui-transition), border-color var(--ui-transition), box-shadow var(--ui-transition);
}

.app-shell .btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.app-shell .btn:focus-visible,
.app-shell .form-control:focus,
.app-shell .form-select:focus,
.app-shell .form-check-input:focus {
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15) !important;
}

.app-shell .btn-apple-primary,
.app-shell .btn-primary {
    border-color: var(--ui-blue) !important;
    color: #fff !important;
    background: var(--ui-blue) !important;
    box-shadow: none !important;
}

.app-shell .btn-apple-primary:hover,
.app-shell .btn-primary:hover {
    border-color: var(--ui-blue-hover) !important;
    background: var(--ui-blue-hover) !important;
}

.app-shell .btn-apple-secondary,
.app-shell .btn-outline-secondary,
.app-shell .btn-light {
    border-color: var(--ui-line) !important;
    color: var(--ui-ink) !important;
    background: #fff !important;
}

.app-shell .btn-apple-secondary:hover,
.app-shell .btn-outline-secondary:hover,
.app-shell .btn-light:hover {
    background: #f2f2f7 !important;
    border-color: rgba(29, 29, 31, 0.2) !important;
}

.app-shell .btn-apple-success,
.app-shell .btn-success {
    border-color: var(--ui-green) !important;
    color: #fff !important;
    background: var(--ui-green) !important;
}

.app-shell .btn-apple-danger,
.app-shell .btn-danger,
.app-shell .btn-outline-danger {
    border-color: var(--ui-red) !important;
    color: #fff !important;
    background: var(--ui-red) !important;
}

.app-shell .btn-outline-danger {
    color: var(--ui-red) !important;
    background: #fff !important;
}

.app-shell .btn-outline-danger:hover {
    color: #fff !important;
    background: var(--ui-red) !important;
}

.app-shell .btn-sm {
    min-height: 32px;
    font-size: 12px;
}

/* Inputs and data entry ------------------------------------- */
.app-shell .form-label {
    margin-bottom: 7px;
    color: var(--ui-muted);
    font-size: 13px;
    font-weight: 600;
}

.app-shell .form-control,
.app-shell .form-select,
.app-shell .input-group-text {
    min-height: 44px;
    border-color: var(--ui-line);
    border-radius: 12px;
    color: var(--ui-ink);
    background: #fff;
    font-size: 14px;
}

.app-shell .form-control,
.app-shell .form-select {
    padding: 9px 12px;
}

.app-shell textarea.form-control {
    min-height: 96px;
}

.app-shell .form-control::placeholder {
    color: #a1a1a6;
}

.app-shell .form-control:hover,
.app-shell .form-select:hover {
    border-color: rgba(29, 29, 31, 0.22);
}

.app-shell .form-control:focus,
.app-shell .form-select:focus {
    border-color: var(--ui-blue) !important;
}

.app-shell .computed-field[readonly] {
    background: #f5f5f7;
    color: var(--ui-muted);
    cursor: default;
    font-variant-numeric: tabular-nums;
}

.app-shell .input-group > .form-control,
.app-shell .input-group > .form-select {
    border-radius: 12px;
}

.app-shell .form-check-input {
    width: 18px;
    height: 18px;
    margin-top: 0;
    border-color: rgba(29, 29, 31, 0.28);
}

.app-shell .form-check-input:checked {
    border-color: var(--ui-blue);
    background-color: var(--ui-blue);
}

.app-shell .form-text,
.app-shell .text-muted,
.app-shell .text-tertiary-apple {
    color: var(--ui-subtle) !important;
}

.app-shell .time-picker-control {
    gap: 8px;
}

.app-shell .time-picker-control .form-select {
    min-width: 86px;
}

.app-shell .thai-date-picker-trigger {
    color: var(--ui-blue);
}

/* Tabs, table and status ------------------------------------ */
.app-shell .app-tabs {
    gap: 8px;
    padding-bottom: 4px;
}

.app-shell .app-tabs .nav-link {
    border-color: var(--ui-line-soft);
    border-radius: 999px;
    color: var(--ui-muted);
    background: rgba(255, 255, 255, 0.72);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
}

.app-shell .app-tabs .nav-link:hover {
    color: var(--ui-ink);
    background: #fff;
}

.app-shell .app-tabs .nav-link.active {
    border-color: #1d1d1f;
    color: #fff;
    background: #1d1d1f;
}

.app-shell .app-table thead th,
.app-shell .table thead th {
    padding: 13px 16px;
    border-bottom-color: var(--ui-line-soft);
    color: var(--ui-muted);
    background: var(--ui-surface-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.app-shell .app-table tbody td,
.app-shell .table tbody td {
    padding: 15px 16px;
    border-bottom-color: var(--ui-line-soft);
    color: var(--ui-ink);
    font-size: 13px;
}

.app-shell .app-table tbody tr:hover,
.app-shell .table-hover > tbody > tr:hover > * {
    color: var(--ui-ink);
    background: #fafafa;
}

.app-shell .status-badge,
.app-shell .ai-badge,
.app-shell .action-chip,
.app-shell .role-badge {
    font-size: 11px;
    font-weight: 700;
}

.app-shell .status-badge {
    padding: 5px 10px;
}

.app-shell .pagination .page-link {
    min-width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border-color: var(--ui-line-soft);
    color: var(--ui-ink);
    background: #fff;
    font-size: 12px;
}

.app-shell .pagination .page-item:first-child .page-link {
    border-radius: 10px 0 0 10px;
}

.app-shell .pagination .page-item:last-child .page-link {
    border-radius: 0 10px 10px 0;
}

.app-shell .pagination .page-item.active .page-link {
    border-color: var(--ui-blue);
    background: var(--ui-blue);
}

/* Filters, alerts and modals -------------------------------- */
.app-shell .document-filter-bar {
    padding: 12px 14px;
    border-color: var(--ui-line-soft);
    border-radius: var(--ui-radius-md);
    background: rgba(255, 255, 255, 0.8);
    box-shadow: var(--ui-shadow-sm);
}

.app-shell .document-filter-toggle {
    min-height: 40px;
    border-color: var(--ui-line);
    border-radius: 11px;
    background: var(--ui-surface-muted);
    font-size: 13px;
    font-weight: 600;
}

.app-shell .document-filter-menu {
    min-width: min(370px, calc(100vw - 36px));
}

.app-shell .alert {
    border: 1px solid transparent;
    border-radius: 14px;
    font-size: 13px;
}

.app-shell .alert-success {
    border-color: rgba(36, 138, 61, 0.2);
    color: #1a6a30;
    background: #f1faf3;
}

.app-shell .alert-danger {
    border-color: rgba(215, 0, 21, 0.18);
    color: #a30d1b;
    background: #fff5f5;
}

.app-shell .alert-warning {
    border-color: rgba(200, 104, 0, 0.2);
    color: #8c4a00;
    background: #fff9ec;
}

.app-shell .alert-info {
    border-color: rgba(0, 113, 227, 0.18);
    color: #005aa8;
    background: #f2f8ff;
}

.app-shell .modal-content {
    overflow: hidden;
    border: 1px solid var(--ui-line-soft);
    border-radius: var(--ui-radius-lg);
    box-shadow: var(--ui-shadow-md);
}

.app-shell .modal-header,
.app-shell .modal-footer {
    border-color: var(--ui-line-soft);
}

/* Profile and administration -------------------------------- */
.app-shell .nav-pills {
    gap: 5px;
}

.app-shell .nav-pills .nav-link {
    border-radius: 12px;
    color: var(--ui-muted);
    font-size: 13px;
    font-weight: 600;
    padding: 11px 13px;
}

.app-shell .nav-pills .nav-link:hover {
    color: var(--ui-ink);
    background: rgba(29, 29, 31, 0.05);
}

.app-shell .nav-pills .nav-link.active {
    color: #fff;
    background: #1d1d1f;
}

.app-shell .tab-pane-content {
    min-height: 500px;
    padding: 26px;
}

.app-shell .stat-card {
    height: 100%;
    padding: 20px;
}

.app-shell .stat-card .stat-label {
    color: var(--ui-subtle);
    font-size: 12px;
    font-weight: 600;
}

.app-shell .stat-card .stat-value,
.app-shell .stat-card .stat-num {
    margin-top: 4px;
    color: var(--ui-ink);
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.04em;
}

.app-shell .stat-card.stat-card-approve {
    border-color: rgba(36, 138, 61, 0.18) !important;
    background: #f5fbf6 !important;
}

.app-shell .stat-card.stat-card-approve .stat-num {
    color: #1d7432;
}

.app-shell .stat-card.stat-card-review {
    border-color: rgba(200, 104, 0, 0.2) !important;
    background: #fffaf0 !important;
}

.app-shell .stat-card.stat-card-review .stat-num {
    color: #a85700;
}

.app-shell .stat-card.stat-card-reject {
    border-color: rgba(215, 0, 21, 0.16) !important;
    background: #fff6f6 !important;
}

.app-shell .stat-card.stat-card-reject .stat-num {
    color: #c20d20;
}

/* Empty / public utility pages ------------------------------ */
.app-shell.auth-shell,
.app-shell.error-shell {
    display: flex;
    flex-direction: column;
}

.app-shell .public-nav {
    position: sticky;
    top: 0;
}

.app-shell .auth-page,
.app-shell .error-page {
    width: min(100% - 32px, 640px);
    margin: auto;
    padding: 72px 0;
}

.app-shell .empty-illustration {
    display: inline-grid;
    width: 76px;
    height: 76px;
    place-items: center;
    border-radius: 22px;
    color: var(--ui-blue);
    background: #eaf4ff;
    font-size: 32px;
}

@media (max-width: 991.98px) {
    .app-shell .app-navbar .navbar-collapse {
        padding: 10px 0 2px;
    }

    .app-shell .app-navbar .navbar-nav {
        align-items: stretch !important;
    }

    .app-shell .app-navbar .nav-link {
        padding: 10px 11px !important;
    }

    .app-shell .app-user-menu {
        width: fit-content;
        margin-top: 4px;
    }
}

@media (max-width: 767.98px) {
    .app-shell .page-container,
    .app-shell .profile-container,
    .app-shell .admin-container,
    .app-shell .create-user-container {
        padding-top: 30px !important;
        padding-right: 16px !important;
        padding-bottom: 48px !important;
        padding-left: 16px !important;
    }

    .app-page-header,
    .app-shell .page-header {
        align-items: flex-start;
        flex-direction: column;
        margin-bottom: 24px;
    }

    .app-shell .page-title,
    .app-shell h1.page-title {
        font-size: 30px;
    }

    .app-shell .page-subtitle {
        font-size: 14px;
    }

    .app-shell .app-card,
    .app-shell .card,
    .app-shell .tab-pane-content,
    .app-shell .stat-card {
        border-radius: 16px !important;
    }

    .app-shell .app-card .card-header,
    .app-shell .card > .card-header,
    .app-shell .app-card .card-body,
    .app-shell .card > .card-body,
    .app-shell .tab-pane-content {
        padding: 18px;
    }

    .app-shell .nav-pills {
        flex-direction: row !important;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 7px;
    }

    .app-shell .nav-pills .nav-link {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .app-shell .app-table thead th,
    .app-shell .app-table tbody td,
    .app-shell .table thead th,
    .app-shell .table tbody td {
        padding: 12px;
    }

    .app-brand-copy small,
    .app-user-role {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-shell *,
    .app-shell *::before,
    .app-shell *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
