:root {
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: #172033;
    background: #f3f6fa;
    font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: #f3f6fa; color: #172033; }
a { color: #155fa0; text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar { background: #102a43; color: white; padding: 24px 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 24px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand-mark, .login-brand { width: 46px; height: 46px; border-radius: 12px; background: #dbeafe; color: #102a43; display: grid; place-items: center; font-weight: 800; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; font-size: 12px; color: #bdd1e4; margin-top: 4px; }
.nav-menu { margin-top: 18px; display: grid; gap: 6px; }
.nav-menu a { color: #d8e8f6; padding: 11px 13px; border-radius: 8px; font-weight: 600; }
.nav-menu a:hover, .nav-menu a.active { background: #1d4f75; color: white; text-decoration: none; }

.main-content { min-width: 0; }
.topbar { height: 68px; background: white; border-bottom: 1px solid #e3e8ef; display: flex; align-items: center; justify-content: space-between; padding: 0 30px; position: sticky; top: 0; z-index: 10; }
.topbar-title { font-weight: 700; }
.user-box { display: flex; gap: 14px; align-items: center; font-size: 14px; }
.page-content { padding: 28px 30px 48px; }
h1 { margin: 0 0 6px; font-size: 28px; }
h2 { margin: 0; font-size: 18px; }
.page-subtitle { margin: 0 0 24px; color: #64748b; }
.page-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.page-heading .page-subtitle { margin-bottom: 0; }

/* ===== Nút ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 40px; padding: 0 16px;
    border: 1px solid #d0d9e4; border-radius: 9px;
    background: #fff; color: #1e293b;
    font: inherit; font-size: 14px; font-weight: 600; line-height: 1;
    cursor: pointer; white-space: nowrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: #f4f7fb; border-color: #b8c4d3; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(21, 95, 160, .25); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary {
    background: linear-gradient(180deg, #1b6cb3 0%, #155fa0 100%);
    border-color: #135591; color: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .12), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-primary:hover { background: linear-gradient(180deg, #175f9f 0%, #0f4f89 100%); border-color: #0f4f89; }
.btn-danger { color: #b42318; border-color: #f5c2c0; background: #fff; }
.btn-danger:hover { background: #fef2f2; border-color: #ef9a96; color: #991b1b; }
.btn-small { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 7px; }

.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(140px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: white; border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; }
.stat-card span { display: block; color: #64748b; font-size: 13px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 28px; }
.stat-card.danger { border-left: 4px solid #dc2626; }
.stat-card.success { border-left: 4px solid #16a34a; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel, .form-panel { background: white; border: 1px solid #e2e8f0; border-radius: 12px; }
.panel { overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid #e2e8f0; }
.table-panel { margin-top: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid #edf1f5; vertical-align: top; font-size: 13px; }
th { background: #f8fafc; color: #475569; font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: #fbfdff; }
.summary-cell { min-width: 260px; max-width: 480px; }
.actions { white-space: nowrap; display: flex; gap: 6px; }
/* Ô bảng phải giữ display: table-cell, nếu không ô thao tác lệch khỏi hàng. */
td.actions { display: table-cell; }
td.actions > * + * { margin-left: 6px; }
.page-heading > .btn { white-space: nowrap; flex-shrink: 0; }
.empty-cell { text-align: center; color: #64748b; padding: 30px; }
.row-overdue { background: #fff7f7; }

.status { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-neutral { background: #e8eef5; color: #334155; }
.status-success { background: #dcfce7; color: #166534; }
.status-warning { background: #fef3c7; color: #92400e; }
.status-danger { background: #fee2e2; color: #991b1b; }
.status-info { background: #dbeafe; color: #1e40af; }
.muted { color: #64748b; }

.filter-bar { display: flex; gap: 10px; margin: 16px 0; }
.filter-bar input { flex: 1; min-width: 180px; }
.filter-bar select { flex: 0 1 240px; width: auto; min-width: 150px; }
/* ===== Ô nhập, dropdown, chọn ngày ===== */
input, select, textarea {
    width: 100%; border: 1px solid #d0d9e4; border-radius: 9px;
    padding: 0 12px; font: inherit; font-size: 14px; color: #172033; background-color: #fff;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, .04);
    transition: border-color .15s, box-shadow .15s, background-color .15s;
}
input, select { height: 40px; }
textarea { padding: 10px 12px; line-height: 1.5; resize: vertical; }
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:hover, select:hover, textarea:hover { border-color: #b8c4d3; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .18);
}
input:disabled, select:disabled, textarea:disabled {
    background-color: #f1f5f9; color: #64748b; border-color: #e2e8f0; cursor: not-allowed; box-shadow: none;
}

/* Dropdown: bỏ mũi tên mặc định, dùng mũi tên thống nhất trên mọi trình duyệt. */
select {
    appearance: none; -webkit-appearance: none;
    padding-right: 36px; cursor: pointer; text-overflow: ellipsis;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 13px center; background-size: 12px 8px;
}
select:disabled { cursor: not-allowed; opacity: 1; }
select option { color: #172033; }
select optgroup { font-weight: 700; color: #475569; }

/* Chọn ngày: biểu tượng lịch đồng màu, dễ bấm. */
input[type="date"], input[type="datetime-local"] { cursor: pointer; padding-right: 10px; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer; opacity: .55; padding: 4px; border-radius: 6px; transition: opacity .15s, background-color .15s;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover { opacity: .9; background-color: #e8f0fb; }
input[type="date"]::-webkit-datetime-edit-fields-wrapper { padding: 0; }
input[type="date"]:invalid::-webkit-datetime-edit, input[type="date"]:not(:valid)::-webkit-datetime-edit { color: #94a3b8; }

/* Ô ngày dd/MM/yyyy (component DateInput): ô gõ + biểu tượng lịch mở bộ chọn ngày. */
.date-input { position: relative; }
.date-input > input[type="text"] { padding-right: 42px; font-variant-numeric: tabular-nums; letter-spacing: .2px; }
.date-input-picker {
    position: absolute; top: 4px; right: 4px; bottom: 4px; width: 34px;
    display: grid; place-items: center; border-radius: 7px; color: #64748b;
    transition: background-color .15s, color .15s;
}
.date-input-picker:hover { background: #e8f0fb; color: #155fa0; }
.date-input-picker > input[type="date"] {
    position: absolute; inset: 0; width: 100%; height: 100%;
    margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; box-shadow: none;
}
.date-input-picker > input[type="date"]::-webkit-calendar-picker-indicator {
    position: absolute; inset: 0; width: auto; height: auto; margin: 0; padding: 0; cursor: pointer; opacity: 0;
}
.date-input.is-disabled .date-input-picker { color: #cbd5e1; pointer-events: none; }

/* Ô nhập sai (validation của form) */
input.invalid, select.invalid, textarea.invalid { border-color: #f87171; }
input.invalid:focus, select.invalid:focus, textarea.invalid:focus { box-shadow: 0 0 0 3px rgba(248, 113, 113, .2); }

/* Checkbox */
input[type="checkbox"] {
    width: 17px; height: 17px; margin: 0; padding: 0; box-shadow: none;
    accent-color: #155fa0; cursor: pointer; flex-shrink: 0;
}
td input[type="checkbox"] { vertical-align: middle; }
.form-panel { padding: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: grid; gap: 7px; align-content: start; }
.field label { font-size: 13px; font-weight: 700; color: #334155; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid #e2e8f0; }
.validation-message, .validation-summary { color: #b42318; font-size: 12px; }
.field-hint { color: #64748b; font-size: 12px; }
.summary-cell .field-hint { display: block; margin-top: 4px; }

.attachment-panel { margin-top: 18px; }
.attachment-upload { display: grid; gap: 6px; padding: 16px; }
.attachment-message { margin: 0 16px 12px; }
.attachment-panel .catalog-list a { font-weight: 600; }

.viewer-heading { align-items: flex-start; }
.viewer-heading h1 { word-break: break-word; }
.doc-viewer { display: block; width: 100%; height: calc(100vh - 210px); min-height: 480px; border: 1px solid #dce3eb; border-radius: 12px; background: white; }
.doc-viewer-image { display: grid; place-items: center; overflow: auto; padding: 12px; }
.doc-viewer-image img { max-width: 100%; height: auto; }

.catalog-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 16px; }
.stack-form { display: grid; gap: 8px; padding: 16px; }
.catalog-list { list-style: none; margin: 0; padding: 0 16px 16px; }
.catalog-list li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid #edf1f5; }
.catalog-list small { display: block; color: #64748b; margin-top: 3px; }
.user-create-panel { padding: 20px; margin-bottom: 18px; }
.user-create-panel h2 { margin-bottom: 16px; }
.form-message { margin-left: 12px; color: #166534; font-weight: 600; }
.page-message { margin: 0 0 12px; }
.cell-hint { display: block; margin-top: 4px; }

/* Popup thêm/sửa */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100; }
.modal {
    position: fixed; z-index: 101; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
    display: flex; flex-direction: column;
    background: white; border-radius: 14px; box-shadow: 0 24px 70px rgba(15, 42, 67, .25);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid #e2e8f0; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: #64748b; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: #f1f5f9; color: #172033; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-error { margin: 0 0 14px; font-size: 13px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid #e2e8f0; }

@media (max-width: 600px) {
    .modal .form-grid { grid-template-columns: 1fr; }
    .modal .span-2 { grid-column: auto; }
}

.loading, .empty-state, .auth-message { background: white; border: 1px solid #e2e8f0; padding: 30px; border-radius: 12px; text-align: center; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #e8f0f8, #f8fafc); }
.login-card { width: min(420px, 100%); background: white; border: 1px solid #dce3eb; border-radius: 16px; padding: 30px; box-shadow: 0 20px 60px rgba(15, 42, 67, .12); }
.login-card h1 { margin-top: 16px; font-size: 24px; }
.login-card p { color: #64748b; margin: 6px 0 22px; }
.login-card form { display: grid; gap: 9px; }
.login-card label { font-weight: 700; font-size: 13px; margin-top: 6px; }
.login-button { margin-top: 12px; width: 100%; }

@media (max-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
    .catalog-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 850px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .nav-menu { grid-template-columns: repeat(2, 1fr); }
    .topbar { position: static; padding: 0 18px; }
    .page-content { padding: 20px 16px 36px; }
    .stat-grid, .panel-grid, .catalog-grid, .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .page-heading, .filter-bar { flex-direction: column; }
    .filter-bar > * { width: 100%; }
}

/* Chọn nhiều quyền cho một tài khoản */
.role-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Ô chọn dạng "chip": cả nhãn bấm được, đổi màu khi được chọn. */
.field label.role-check, .role-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid #d0d9e4;
    border-radius: 9px;
    background: #fff;
    font-size: 13.5px;
    font-weight: 500;
    color: #1e293b;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
    justify-self: start;
}

.role-check:hover { background: #f4f7fb; border-color: #b8c4d3; }
.role-check:has(input:checked) { background: #eff6ff; border-color: #93c5fd; color: #1e40af; }
