:root {
    --sidebar-width: 260px;
    --sidebar-bg: #1c1917;
    --sidebar-header-bg: #1a0a0a;
    --accent-gold: #c9a84c;
    --accent-gold-light: #e8c97a;
    --accent-red: #8b1a1a;
    --accent-red-light: #b22222;
    --text-muted-sidebar: rgba(255, 255, 255, 0.5);
    --border-sidebar: rgba(201, 168, 76, 0.2);
}

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

body {
    background-color: #f5f0eb;
    font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
    color: #2c2c2c;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--sidebar-bg);
    color: white;
    display: none;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.3);
}

@media (min-width: 768px) {
    .sidebar { display: flex; }
}

.sidebar-brand {
    padding: 24px 20px 20px;
    background: var(--sidebar-header-bg);
    border-bottom: 1px solid var(--border-sidebar);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-brand::before {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 100px;
    height: 100px;
    background: var(--accent-red);
    opacity: 0.15;
    border-radius: 50%;
}

.brand-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.brand-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent-gold);
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.brand-subtitle {
    font-size: 11px;
    color: var(--text-muted-sidebar);
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted-sidebar);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 12px 20px 6px;
}

.sidebar-nav-list {
    list-style: none;
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    margin: 1px 0;
}

.sidebar-nav-link .nav-icon {
    width: 18px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
}

.sidebar-nav-link:hover {
    color: white;
    background: rgba(255, 255, 255, 0.07);
    border-left-color: var(--accent-gold);
}

.sidebar-nav-link.active {
    color: var(--accent-gold);
    background: rgba(201, 168, 76, 0.1);
    border-left-color: var(--accent-gold);
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-sidebar);
    font-size: 11px;
    color: var(--text-muted-sidebar);
    text-align: center;
    flex-shrink: 0;
}

/* ─── Main content ─── */
.main-content {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .main-content { margin-left: var(--sidebar-width); }
}

/* ─── Top Navbar ─── */
.top-navbar {
    background: white;
    border-bottom: 1px solid #ede8e0;
    padding: 0 28px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
}

.page-title {
    font-size: 16px;
    font-weight: 600;
    color: #2c2c2c;
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-title::before {
    content: '';
    width: 4px;
    height: 18px;
    background: linear-gradient(to bottom, var(--accent-red), var(--accent-red-light));
    border-radius: 2px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-red), var(--accent-red-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: #555;
}

.btn-logout {
    font-size: 12px;
    padding: 5px 14px;
    border: 1px solid #ddd;
    background: white;
    color: #666;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-logout:hover {
    border-color: var(--accent-red-light);
    color: var(--accent-red-light);
}

/* ─── Page content ─── */
.page-content {
    padding: 28px;
    flex: 1;
}

/* ─── Stats grid ─── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

@media (min-width: 576px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
    border: 1px solid #ede8e0;
    transition: box-shadow 0.2s;
}

.stat-card:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.red   { background: #fdf0f0; color: var(--accent-red-light); }
.stat-icon.gold  { background: #fdf8ee; color: var(--accent-gold); }
.stat-icon.blue  { background: #eff6ff; color: #3b82f6; }

.stat-label { font-size: 12px; color: #888; margin-bottom: 2px; }
.stat-value { font-size: 22px; font-weight: 700; color: #1c1917; line-height: 1; }

/* ─── Main card ─── */
.main-card {
    background: white;
    border-radius: 14px;
    border: 1px solid #ede8e0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.main-card-header {
    padding: 18px 24px;
    border-bottom: 1px solid #f0ebe3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #faf8f5;
}

.main-card-title {
    font-size: 15px;
    font-weight: 600;
    color: #1c1917;
    display: flex;
    align-items: center;
    gap: 8px;
}

.main-card-title i { color: var(--accent-red-light); }

.main-card-body { padding: 20px 24px; }

/* ─── Search bar ─── */
.search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    max-width: 320px;
}

.search-wrap .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa;
    font-size: 15px;
    pointer-events: none;
}

.search-wrap input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid #e5ddd5;
    border-radius: 8px;
    background: #faf8f5;
    font-size: 14px;
    transition: all 0.2s;
    outline: none;
    font-family: inherit;
}

.search-wrap input:focus {
    border-color: var(--accent-gold);
    background: white;
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.12);
}

.search-filter-hint {
    font-size: 13px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ─── Add button ─── */
.btn-add {
    background: linear-gradient(135deg, var(--accent-red), var(--accent-red-light));
    border: none;
    color: white;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(139, 26, 26, 0.3);
    font-family: inherit;
    text-decoration: none;
}

.btn-add:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(139, 26, 26, 0.4);
}

/* ─── Table ─── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.members-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.members-table thead th {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #888;
    background: #f7f3ef;
    border-bottom: 2px solid #ede8e0;
    white-space: nowrap;
}

.members-table tbody tr {
    border-bottom: 1px solid #f0ebe3;
    transition: background 0.15s;
}

.members-table tbody tr:last-child { border-bottom: none; }
.members-table tbody tr:hover { background: #fdf8f2; }

.members-table td {
    padding: 12px 14px;
    vertical-align: middle;
}

.member-name {
    font-weight: 600;
    color: #1c1917;
    font-size: 14px;
}

.gender-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.gender-male   { background: #eff6ff; color: #2563eb; }
.gender-female { background: #fdf2f8; color: #be185d; }

.birthday-solar { font-size: 13px; color: #333; }
.birthday-lunar { font-size: 11px; color: #999; margin-top: 2px; }

.mobile-text { font-family: monospace; font-size: 13px; color: #444; letter-spacing: 0.5px; }

.address-text { font-size: 12px; color: #666; max-width: 200px; }

/* ─── Action buttons ─── */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    font-family: inherit;
    text-decoration: none;
}

.action-btn-edit {
    background: #f3f4f6;
    color: #555;
    border-color: #e5e7eb;
}

.action-btn-edit:hover {
    background: #e5e7eb;
    color: #222;
}

.action-btn-tree {
    background: #fdf8ee;
    color: var(--accent-gold);
    border-color: #f0e5c0;
}

.action-btn-tree:hover {
    background: #f5edcc;
    color: #a07820;
}

/* ─── Quick link cards (dashboard) ─── */
.quick-link-card {
    background: #faf8f5;
    border: 1px solid #ede8e0;
    border-radius: 12px;
    padding: 20px 16px;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.quick-link-card:hover {
    background: white;
    border-color: var(--accent-gold);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

/* ─── Empty state ─── */
.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: #bbb;
}

.empty-state i { font-size: 48px; margin-bottom: 12px; display: block; opacity: 0.4; }
.empty-state p { font-size: 14px; line-height: 1.8; }

/* ─── Delete action button ─── */
.action-btn-delete {
    background: #fff5f5;
    color: #e53e3e;
    border-color: #fed7d7;
}
.action-btn-delete:hover {
    background: #fed7d7;
    color: #c53030;
}

/* ─── Flash messages ─── */
[x-cloak] { display: none !important; }

.flash-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.flash-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.flash-error {
    background: #fff5f5;
    color: #c53030;
    border: 1px solid #fed7d7;
}

/* ─── Drawer overlay ─── */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1998;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ─── Form Modal (centred, responsive) ─── */
.form-drawer {
    container-type: inline-size;
    container-name: form-modal;

    position: fixed;
    top: 50%;
    left: 50%;
    /* 70vw max, shrinks on small screens, never smaller than 320px */
    width: clamp(320px, 70vw, 860px);
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 48px);
    background: white;
    z-index: 1999;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
    transform: translate(-50%, -48%) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                opacity   0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-drawer.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #ede8e0;
    flex-shrink: 0;
    background: #faf8f5;
    border-radius: 16px 16px 0 0;
}

.drawer-title {
    font-size: 16px;
    font-weight: 700;
    color: #1c1917;
    display: flex;
    align-items: center;
    gap: 8px;
}

.drawer-title i { color: var(--accent-red-light); }

.drawer-close {
    width: 32px;
    height: 32px;
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    font-size: 14px;
    transition: all 0.15s;
}

.drawer-close:hover { background: #f3f4f6; color: #333; }

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.drawer-footer {
    padding: 16px 24px;
    border-top: 1px solid #ede8e0;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
    background: #faf8f5;
    border-radius: 0 0 16px 16px;
}

/* ─── Form sections ─── */
.form-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid #f0ebe3;
}

.form-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.form-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-red-light);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 14px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

/* ─── 表單欄位自適應 (Container Queries) ─── */
/* drawer（form-modal） */
@container form-modal (max-width: 559px) {
    .form-row-3 { grid-template-columns: 1fr 1fr; }
}
@container form-modal (max-width: 399px) {
    .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

/* 頁面表單（form-page） */
@container form-page (max-width: 559px) {
    .form-row-3 { grid-template-columns: 1fr 1fr; }
}
@container form-page (max-width: 399px) {
    .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 10px;
    position: relative;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
}

.form-label.required::after {
    content: ' *';
    color: var(--accent-red-light);
}

.form-input {
    padding: 8px 12px;
    border: 1px solid #e5ddd5;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #faf8f5;
    color: #1c1917;
    transition: all 0.2s;
    outline: none;
    width: 100%;
}

.form-input:focus {
    border-color: var(--accent-gold);
    background: white;
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.12);
}

.form-input.input-error {
    border-color: #e53e3e;
    background: #fff5f5;
}

.form-error {
    font-size: 11px;
    color: #e53e3e;
    margin-top: 2px;
}

.radio-group {
    display: flex;
    gap: 20px;
    padding: 9px 0;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
}

/* ─── Drawer action buttons ─── */
.btn-cancel {
    padding: 8px 20px;
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: #555;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.btn-cancel:hover { background: #f3f4f6; }

.btn-save {
    padding: 8px 22px;
    background: linear-gradient(135deg, var(--accent-red), var(--accent-red-light));
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    box-shadow: 0 2px 8px rgba(139, 26, 26, 0.3);
}

.btn-save:hover { box-shadow: 0 4px 14px rgba(139, 26, 26, 0.4); }
.btn-save:disabled { opacity: 0.6; cursor: not-allowed; }

/* ─── Delete confirmation modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-box {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 400px;
    max-width: calc(100vw - 32px);
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: popIn 0.2s ease;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.modal-icon-wrap {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin: 0 auto 16px;
}

.modal-icon-wrap.danger { background: #fff5f5; color: #e53e3e; }

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #1c1917;
    margin-bottom: 10px;
}

.modal-body {
    font-size: 14px;
    color: #666;
    line-height: 1.7;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-danger {
    padding: 9px 22px;
    background: #e53e3e;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}

.btn-danger:hover { background: #c53030; }
.btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-success {
    padding: 9px 22px;
    background: #16a34a;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}
.btn-success:hover { background: #15803d; }

/* ─── Activate action button ─── */
.action-btn-activate {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0;
}
.action-btn-activate:hover { background: #bbf7d0; }

/* ─── Role badges ─── */
.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.role-admin  { background: #fdf0f0; color: var(--accent-red-light); }
.role-editor { background: #eff6ff; color: #2563eb; }
.role-viewer { background: #f3f4f6; color: #6b7280; }

/* ─── Status badges ─── */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.status-active    { background: #f0fdf4; color: #16a34a; }
.status-suspended { background: #fef2f2; color: #dc2626; }

/* ═══════════════════════════════════════════════════════════
   Auth / Login page
═══════════════════════════════════════════════════════════ */
.auth-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a0a0a 0%, #2a0808 40%, #1c1917 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.auth-deco {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(201, 168, 76, 0.15);
    pointer-events: none;
}
.auth-deco-1 { width: 500px; height: 500px; top: -200px; right: -150px; }
.auth-deco-2 { width: 300px; height: 300px; bottom: -100px; left: -100px; border-color: rgba(139, 26, 26, 0.2); }
.auth-deco-3 { width: 200px; height: 200px; top: 50%; right: 10%; transform: translateY(-50%); }

.auth-card {
    background: white;
    border-radius: 20px;
    padding: 40px;
    width: 420px;
    max-width: 100%;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 1;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}

.auth-logo-title {
    font-size: 20px;
    font-weight: 700;
    color: #1c1917;
    margin-bottom: 4px;
}

.auth-logo-sub {
    font-size: 12px;
    color: #aaa;
}

.auth-error {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff5f5;
    border: 1px solid #fed7d7;
    color: #c53030;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 20px;
}

.auth-form { margin-top: 4px; }

/* ─── Modal icon success variant ─── */
.modal-icon-wrap.success { background: #f0fdf4; color: #16a34a; }

/* ══════════════════════════════════════════════════════════════
   Permission Matrix
   ══════════════════════════════════════════════════════════════ */

.perm-header {
    display: grid;
    grid-template-columns: 1fr 120px 120px 120px;
    align-items: center;
    padding: 12px 20px;
    background: #faf8f5;
    border-bottom: 1px solid #ede8e0;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    position: sticky;
    top: 0;
    z-index: 2;
}

.perm-col-label {
    padding-right: 16px;
}

.perm-col-role {
    text-align: center;
}

.role-admin-col  { color: var(--accent-red); }
.role-editor-col { color: #2563eb; }
.role-viewer-col { color: #6b7280; }

.perm-group {
    border-bottom: 1px solid #f0ece6;
}

.perm-group-title {
    padding: 10px 20px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--accent-gold);
    background: #fdf9f3;
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid #f0ece6;
}

.perm-row {
    display: grid;
    grid-template-columns: 1fr 120px 120px 120px;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid #f7f3ef;
    transition: background .15s;
}

.perm-row:last-child { border-bottom: none; }

.perm-row:hover { background: #fdfaf7; }

.perm-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}

.perm-code {
    display: block;
    font-size: 11px;
    color: #aaa;
    font-family: ui-monospace, monospace;
    margin-top: 2px;
}

/* Custom checkbox toggle */
.perm-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    width: 36px;
    height: 36px;
    margin: 0 auto;
}

.perm-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.perm-checkmark {
    width: 22px;
    height: 22px;
    border: 2px solid #d1d5db;
    border-radius: 6px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    flex-shrink: 0;
}

.perm-checkmark::after {
    content: '';
    display: block;
    width: 6px;
    height: 10px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translateY(-1px);
    opacity: 0;
    transition: opacity .15s;
}

.perm-toggle input:checked ~ .perm-checkmark {
    background: var(--accent-red);
    border-color: var(--accent-red);
}

.perm-toggle input:checked ~ .perm-checkmark::after {
    opacity: 1;
}

.perm-toggle input:disabled ~ .perm-checkmark {
    opacity: .45;
    cursor: not-allowed;
}

.perm-toggle:hover .perm-checkmark {
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(139, 26, 26, .1);
}

/* ══════════════════════════════════════════════════════════════
   Father Searchable Dropdown
   ══════════════════════════════════════════════════════════════ */

.father-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    min-height: 40px;
    transition: border-color .15s;
    position: relative;
}

.father-select-trigger:hover {
    border-color: #d1d5db;
}

.father-select-trigger:focus-within,
.father-select-trigger:has(+ .father-select-dropdown[style*="display: block"]) {
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(139, 26, 26, .08);
}

.father-select-dropdown {
    position: absolute;
    z-index: 50;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: white;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .1);
    overflow: hidden;
}

.father-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid #f0ece6;
}

.father-search-input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 13px;
    color: #374151;
    background: transparent;
}

.father-search-input::placeholder { color: #ccc; }

.father-option-list {
    max-height: 200px;
    overflow-y: auto;
}

.father-option {
    padding: 9px 14px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background .1s;
}

.father-option:hover {
    background: #fdf9f3;
    color: var(--accent-red);
}

/* ══════════════════════════════════════════════════════════════
   Family Tree Page
   ══════════════════════════════════════════════════════════════ */

.tree-select-bar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 20px;
    background: white;
    border: 1px solid #ede8e0;
    border-radius: 12px;
    margin-bottom: 14px;
}

.tree-select-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.tree-select-label {
    font-size: 11px;
    font-weight: 700;
    color: #aaa;
    letter-spacing: .05em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tree-select-divider {
    font-size: 13px;
    color: #ccc;
    padding-bottom: 7px;
    font-weight: 500;
}

.tree-clear-btn {
    padding: 7px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    background: white;
    font-size: 13px;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all .15s;
}

.tree-clear-btn:hover {
    border-color: #fca5a5;
    color: #ef4444;
    background: #fff5f5;
}

.btn-tree-dl {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    background: white;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: all .15s;
}

.btn-tree-dl:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
    background: #fdf9f3;
}

.tree-canvas-wrap {
    position: relative;
    width: 100%;
    height: calc(100vh - 290px);
    min-height: 420px;
    background: #fdfaf7;
    border: 1px solid #ede8e0;
    border-radius: 12px;
    overflow: hidden;
    cursor: grab;
}

.tree-canvas-wrap:active { cursor: grabbing; }

.tree-zoom-hint {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: #ccc;
    background: rgba(255, 255, 255, .85);
    padding: 4px 14px;
    border-radius: 20px;
    pointer-events: none;
    z-index: 5;
    white-space: nowrap;
    backdrop-filter: blur(4px);
}

.tree-reset-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: white;
    font-size: 12px;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 5;
    transition: all .15s;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.tree-reset-btn:hover {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

/* ─── Duplicate warning ─── */
.duplicate-warning {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #fffbeb;
    border: 1.5px solid #fde68a;
    color: #92400e;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    margin-top: 10px;
}

.duplicate-warning i {
    flex-shrink: 0;
    margin-top: 1px;
    color: #f59e0b;
}

/* ───────────────────────────────────────────────────── */

.tree-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 290px);
    min-height: 420px;
    background: #fdfaf7;
    border: 1px solid #ede8e0;
    border-radius: 12px;
    text-align: center;
    padding: 40px;
}

/* ─── 新增/編輯會員頁 ─── */
.form-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.form-page-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: #888;
    text-decoration: none;
    margin-bottom: 6px;
}

.form-page-back:hover {
    color: var(--accent-gold);
}

.form-page-title {
    font-size: 20px;
    font-weight: 700;
    color: #1c1917;
    margin: 0;
}

/* ─── 編輯頁兩欄佈局 ─── */
.edit-layout {
    display: flex;
    gap: 0;
    align-items: flex-start;
    margin: -20px;
}

@media (max-width: 860px) {
    .edit-layout { flex-direction: column; margin: 0; }
}

.edit-side {
    width: 230px;
    flex-shrink: 0;
    background: #fafaf9;
    border-right: 1px solid #f0ece6;
    min-height: calc(100vh - 64px);
    overflow-y: auto;
    position: sticky;
    top: 0;
    max-height: calc(100vh - 64px);
}

@media (max-width: 860px) {
    .edit-side {
        width: 100%;
        min-height: auto;
        max-height: 260px;
        position: static;
        border-right: none;
        border-bottom: 1px solid #f0ece6;
    }
}

.edit-side-header {
    padding: 14px 16px 10px;
    font-size: 11px;
    font-weight: 700;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: sticky;
    top: 0;
    background: #fafaf9;
    z-index: 1;
    border-bottom: 1px solid #f0ece6;
}

.edit-side-item {
    display: block;
    padding: 9px 14px;
    text-decoration: none;
    color: #374151;
    border-left: 3px solid transparent;
    transition: background 0.1s;
    line-height: 1.3;
}

.edit-side-item:hover {
    background: #f5f0ea;
    color: #1c1917;
}

.edit-side-item.active {
    border-left-color: var(--accent-gold);
    background: #fffbeb;
    color: #92400e;
}

.edit-side-item-name {
    font-size: 13px;
    font-weight: 500;
}

.edit-side-item.active .edit-side-item-name {
    font-weight: 700;
}

.edit-side-item-meta {
    font-size: 11px;
    color: #b0a898;
    margin-top: 2px;
}

.edit-main {
    flex: 1;
    padding: 20px 24px;
    min-width: 0;
    overflow-x: hidden;
}

@media (max-width: 860px) {
    .edit-main { padding: 16px; }
}

/* ─── Two-card row (form + receipts side by side) ─── */
.edit-cards-row {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.main-card-form {
    flex: 1 1 0;
    min-width: 380px;
    container-type: inline-size;
    container-name: form-page;
}

.main-card-receipts {
    flex: 0 0 40%;
}

@media (max-width: 860px) {
    .edit-cards-row { flex-direction: column; }
    .main-card-receipts { flex: none; width: 100%; }
}

/* ─── Edit form 2-column layout ─── */

/* 1-col mode: first col's last section needs its border restored */
.form-col-left .form-section:last-child {
    border-bottom: 1px solid #f0ebe3;
    margin-bottom: 24px;
    padding-bottom: 24px;
}

@container form-page (min-width: 620px) {
    .drawer-body {
        display: flex;
        align-items: stretch;
        gap: 0;
    }
    .form-col {
        flex: 1 1 0;
        min-width: 0;
    }
    .form-col-left {
        padding-right: 20px;
        border-right: 1px solid #f0ebe3;
    }
    .form-col-right {
        padding-left: 20px;
    }
    /* Within each narrow column, sub-rows stay single-col */
    .form-col .form-row-2,
    .form-col .form-row-3 {
        grid-template-columns: 1fr;
    }
    /* Restore last-section border handling per column */
    .form-col-left .form-section:last-child {
        border-bottom: none;
        margin-bottom: 0;
        padding-bottom: 0;
    }
}

/* ─── Pagination ─── */
.pagination {
    justify-content: center;
    margin-bottom: 0;
    gap: 2px;
}

.pagination .page-link {
    color: var(--accent-gold);
    border-color: #ede8e0;
    border-radius: 6px !important;
    padding: 5px 12px;
    font-size: 13px;
    transition: all 0.15s;
}

.pagination .page-link:hover {
    background: #fdf8ee;
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

.pagination .page-item.active .page-link {
    background: var(--accent-gold);
    border-color: var(--accent-gold);
    color: white;
}

.pagination .page-item.disabled .page-link {
    color: #ccc;
    border-color: #f0ece6;
    background: #fafaf9;
}

/* ─── Finance module ─── */
.receipt-no-link {
    font-family: monospace;
    font-size: 13px;
    color: var(--accent-gold);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.03em;
}
.receipt-no-link:hover { text-decoration: underline; }

.receipt-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}
.badge-fee   { background: #eff6ff; color: #1d4ed8; }
.badge-other { background: #f0fdf4; color: #15803d; }

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.status-active   { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.status-inactive { background: #f3f4f6; color: #9ca3af; border-color: #e5e7eb; }

.receipt-period-hint {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: #1d4ed8;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

/* ─── 收據列印紙本 ─── */
.receipt-paper {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    max-width: 620px;
    padding: 40px 48px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.06);
}

.receipt-header {
    text-align: center;
    margin-bottom: 28px;
    border-bottom: 2px solid #1c1917;
    padding-bottom: 16px;
}

.receipt-org {
    font-size: 16px;
    font-weight: 700;
    color: #555;
    margin-bottom: 6px;
    letter-spacing: 0.08em;
}

.receipt-title {
    font-size: 28px;
    font-weight: 700;
    color: #1c1917;
    letter-spacing: 0.3em;
}

.receipt-meta {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px dashed #e5e7eb;
}

.receipt-meta-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.receipt-meta-label { color: #888; }
.receipt-meta-value { color: #1c1917; font-weight: 600; }
.receipt-no-large   { font-family: monospace; font-size: 15px; color: var(--accent-gold); }

.receipt-body { margin-bottom: 32px; }

.receipt-line {
    display: flex;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid #f5f0eb;
    font-size: 15px;
    align-items: baseline;
}

.receipt-line-label {
    min-width: 80px;
    color: #888;
    flex-shrink: 0;
    font-size: 13px;
}

.receipt-line-value { color: #1c1917; font-weight: 500; }

.receipt-amount-line  { padding: 14px 0; }
.receipt-amount-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-red-light);
}

.receipt-footer {
    display: flex;
    gap: 24px;
    align-items: flex-end;
    border-top: 1px solid #e5e7eb;
    padding-top: 20px;
}

.receipt-footer-col { flex: 1; }

.receipt-footer-label {
    font-size: 13px;
    color: #888;
    margin-bottom: 28px;
}

.receipt-footer-sign {
    border-bottom: 1px solid #1c1917;
    height: 1px;
}

.receipt-footer-date {
    font-size: 14px;
    color: #555;
    text-align: right;
    white-space: nowrap;
}

/* ─── 列印樣式 ─── */
/* ─── Finance report ─── */
.report-print-header { display: none; }
.report-print-only   { display: none; }

.report-summary-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    border: 1px solid #ede8e0;
    border-radius: 10px;
    padding: 12px 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.report-summary-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-summary-label {
    font-size: 12px;
    color: #aaa;
}

.report-summary-value {
    font-size: 18px;
    font-weight: 700;
    color: #1c1917;
}

.report-summary-sep {
    width: 1px;
    height: 24px;
    background: #ede8e0;
}

.report-table tfoot .report-total-row td {
    border-top: 2px solid #ede8e0;
    padding-top: 10px;
    padding-bottom: 10px;
    background: #faf8f5;
}

@media print {
    .no-print,
    .report-screen-only,
    .sidebar,
    .top-navbar,
    .flash-message { display: none !important; }

    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }

    .receipt-paper {
        border: none;
        box-shadow: none;
        padding: 20px;
        max-width: 100%;
    }

    /* ── Report print layout ── */
    @page { size: A4; margin: 12mm 14mm; }

    .report-print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 16px;
        padding-bottom: 10px;
        border-bottom: 2px solid #1c1917;
    }

    .report-print-org {
        font-size: 14px;
        color: #555;
        margin-bottom: 4px;
    }

    .report-print-title {
        font-size: 20px;
        font-weight: 700;
        letter-spacing: 4px;
        margin-bottom: 6px;
    }

    .report-print-meta {
        font-size: 11px;
        color: #666;
    }

    .report-print-only { display: inline !important; }

    .report-summary-bar {
        border: none;
        padding: 6px 0 10px;
        margin-bottom: 8px;
        font-size: 12px;
    }

    .report-summary-value { font-size: 14px; }

    .main-card {
        border: none;
        box-shadow: none;
    }

    .report-table {
        font-size: 10px;
        width: 100%;
    }

    .report-table th,
    .report-table td {
        padding: 4px 5px;
    }

    .receipt-type-badge {
        border: none;
        background: none;
        padding: 0;
        font-size: 10px;
    }
}
