/* Core reusable components. Load after base.css. */

/* ── App shell ── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    position: sticky; top: 0; z-index: 50;
    display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center;
    min-height: 68px; padding: 0 max(20px, calc((100vw - 1240px) / 2));
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    transition: box-shadow var(--t);
}
.topbar.has-shadow { box-shadow: 0 4px 20px rgba(17, 24, 39, 0.07); }

.brand {
    display: inline-flex; align-items: center; gap: 11px; min-width: max-content;
    font-weight: 900; letter-spacing: -0.03em; color: var(--ink);
}
.brand-mark {
    display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
    color: #fff; background: var(--black); font-size: 0.85rem; font-weight: 900; flex-shrink: 0;
}
.brand-copy { line-height: 1.2; }
.brand-copy small {
    display: block; margin-top: 2px; color: var(--muted);
    font-size: 0.67rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase;
}

.nav { display: flex; align-items: center; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }

.content-frame {
    flex: 1; width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 32px 0 80px;
}

.site-footer {
    margin-top: auto; padding: 28px max(20px, calc((100vw - 1240px) / 2));
    border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 0.82rem;
    display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
}
.site-footer a { color: var(--teal-dark); font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

/* ── Buttons (also styles .nav a as a button-like link) ── */
.nav a, .button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 38px; padding: 0 14px;
    border: 1.5px solid transparent; border-radius: 999px;
    color: var(--muted); background: transparent; cursor: pointer;
    font-size: 0.875rem; font-weight: 600; white-space: nowrap;
    transition: background var(--t), color var(--t), border-color var(--t), transform var(--t), box-shadow var(--t);
}
.nav a:hover, .button:hover { color: var(--ink); background: var(--line-light); }
.nav a.is-current, .nav a.active { color: #fff; background: var(--black); }

.button.primary {
    color: #fff !important; background: var(--teal) !important; border-color: var(--teal) !important;
}
.button.primary:hover {
    background: var(--teal-dark) !important; border-color: var(--teal-dark) !important;
    transform: translateY(-1px); box-shadow: 0 4px 14px rgba(15, 118, 110, 0.32);
}
.button.outline { border-color: var(--line); color: var(--ink-body); }
.button.outline:hover {
    border-color: var(--teal-light); color: var(--teal); background: var(--teal-bg);
    transform: translateY(-1px); box-shadow: var(--shadow-sm);
}
.button.danger { background: #b91c1c !important; color: #fff !important; }
.button.danger:hover { background: #991b1b !important; box-shadow: 0 4px 12px rgba(185, 28, 28, 0.25) !important; }
.button.danger-soft { color: #991b1b; background: #fff1f2; border-color: rgba(185, 28, 28, 0.18); }
.button.danger-soft:hover {
    color: #7f1d1d; background: #ffe4e6; border-color: rgba(185, 28, 28, 0.28);
    transform: translateY(-1px); box-shadow: 0 10px 24px rgba(185, 28, 28, 0.12);
}
.button.info {
    color: var(--ink); background: #f1f5f9; border-color: #e2e8f0; padding: 0 22px; box-shadow: var(--shadow-xs);
}
.button.info:hover {
    color: var(--teal-dark); background: #e2e8f0; border-color: #cbd5e1;
    transform: translateY(-1px); box-shadow: var(--shadow-sm);
}
.button.full-width { width: 100%; }
.button.is-disabled, .button[disabled] {
    opacity: 0.6; cursor: not-allowed; pointer-events: none;
    transform: none !important; box-shadow: none !important;
}

/* ── Layout primitives ── */
.panel {
    padding: clamp(26px, 4vw, 46px);
    border: 1.5px solid var(--line); border-radius: var(--radius-md);
    background: #fff; box-shadow: var(--shadow-sm);
}
.card {
    padding: 26px 28px;
    border: 1.5px solid var(--line); border-radius: var(--radius-md);
    background: #fff; box-shadow: var(--shadow-sm);
}
.card > h2 { margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.section-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px;
}
.section-header h2 { margin: 0; }

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center; gap: 4px; min-height: 22px; padding: 0 9px;
    border-radius: 999px; color: var(--teal-dark); background: var(--teal-bg);
    font-size: 0.71rem; font-weight: 700; letter-spacing: 0.04em; white-space: nowrap;
}
.badge.warn { color: #92400e; background: #fffbeb; }
.badge.danger { color: var(--red); background: #fff1f2; }
.badge.success { color: #065f46; background: #d1fae5; }
.badge.info { color: var(--blue); background: #eff6ff; }

/* ── Alerts ── */
.alert {
    padding: 12px 14px; border-radius: var(--radius-md); border: 1px solid var(--line);
    background: #fff; color: var(--ink); font-size: 0.9rem;
}
.alert.error { border-color: rgba(239, 68, 68, 0.35); background: #fef2f2; color: #991b1b; }
.alert.success { border-color: rgba(16, 185, 129, 0.35); background: #ecfdf5; color: #065f46; }
.alert.warn { border-color: rgba(245, 158, 11, 0.35); background: #fffbeb; color: #92400e; }

/* ── Tables ── */
.table-card {
    position: relative; overflow: hidden;
    border: 1.5px solid var(--line); border-radius: var(--radius-md);
    background: #fff; box-shadow: var(--shadow-sm);
}
.table-header {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 18px 22px; border-bottom: 1px solid var(--line); background: #f9fafb;
}
.table-header h2 { margin: 0; font-size: 0.92rem; font-weight: 700; }
.table-tools { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.table-search {
    width: min(260px, 100%); min-height: 36px; border: 1.5px solid var(--line);
    border-radius: 999px; padding: 0 14px; font-size: 0.85rem; background: #fff; outline: none;
    transition: border-color var(--t), box-shadow var(--t);
}
.table-search:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1); }
.table-count { color: var(--muted); font-size: 0.78rem; font-weight: 700; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line-light); text-align: left; vertical-align: middle; }
th {
    color: var(--muted); background: #f9fafb;
    font-size: 0.69rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; white-space: nowrap;
}
tbody tr { transition: background var(--t); }
tbody tr:hover, tbody tr.is-row-focus { background: var(--teal-bg); }
tr:last-child td { border-bottom: 0; }

/* Sortable header indicator (paired with app.js) */
thead th.is-sortable { position: relative; padding-right: 10px; cursor: pointer; }
thead th.is-sortable::after {
    content: ''; display: inline-block; margin-left: 6px; width: 12px; height: 12px; transform: translateY(1px);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: center; background-size: 11px; opacity: 0.6; pointer-events: none;
}
thead th.is-sorted-asc::after { transform: translateY(1px) rotate(180deg); opacity: 0.95; }
thead th.is-sorted-desc::after { opacity: 0.95; }

/* ── Form layout helpers ── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.span-2 { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: auto; min-height: auto; }
.form-control {
    display: block; width: 100%; padding: 0.5rem 0.75rem; font-size: 0.875rem; line-height: 1.5;
    color: var(--ink-body); background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius-sm); appearance: none;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.form-control:focus { border-color: var(--teal-mid); outline: 0; box-shadow: 0 0 0 0.2rem rgba(13, 148, 136, 0.25); }

/* ── User menu dropdown ── */
.user-menu { position: relative; }
.user-menu-toggle {
    display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px;
    background: var(--teal-bg); border: 1.5px solid var(--teal-light); border-radius: 999px;
    color: var(--teal-dark); cursor: pointer; font-size: 0.82rem; font-weight: 700;
    transition: background var(--t), border-color var(--t);
}
.user-menu-toggle:hover { background: var(--teal-light); border-color: var(--teal); }
.user-menu-avatar {
    display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
    border-radius: 50%; background: var(--teal); color: #fff; font-size: 0.78rem; font-weight: 800; flex-shrink: 0;
}
.user-menu-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0; min-width: 170px;
    background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-md);
    padding: 6px; display: none; z-index: 500;
}
.user-menu.is-open .user-menu-dropdown { display: block; }
.user-menu-dropdown a {
    display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; color: var(--ink); transition: background var(--t);
}
.user-menu-dropdown a:hover { background: var(--teal-bg); color: var(--teal-dark); }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 32px; flex-wrap: wrap; }
.page-link {
    display: grid; place-items: center; min-width: 36px; height: 36px; padding: 0 6px;
    border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    color: var(--muted); font-size: 0.875rem; font-weight: 600;
    transition: background var(--t), color var(--t), border-color var(--t);
}
.page-link:hover { color: var(--ink); border-color: var(--teal-light); background: var(--teal-bg); }
.page-link.active { color: #fff; background: var(--teal); border-color: var(--teal); }
.page-link.is-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.page-ellipsis { color: var(--muted-soft); font-size: 0.875rem; padding: 0 2px; }

/* ── Toast (paired with app.js showToast) ── */
.toast {
    position: fixed; right: 22px; bottom: 22px; z-index: 60;
    max-width: min(360px, calc(100% - 32px)); padding: 13px 18px; border-radius: var(--radius);
    color: #fff; background: var(--black); box-shadow: var(--shadow-lg);
    opacity: 0; transform: translateY(14px); pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
    font-size: 0.875rem; font-weight: 500; line-height: 1.5;
}
.toast.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.toast.is-success { background: var(--teal); }
.toast.is-error { background: var(--red); }

/* ── Modal (generic) ── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px); z-index: 3000;
    display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.is-visible { display: flex; }
.modal {
    background: #fff; width: 100%; max-width: 540px; border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15); padding: 32px; position: relative;
    animation: modal-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-x {
    position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--line); background: #fff; color: var(--muted);
    font-size: 22px; line-height: 1; display: grid; place-items: center; cursor: pointer;
    transition: background var(--t), color var(--t), border-color var(--t);
}
.modal-x:hover { background: var(--teal-bg); color: var(--teal-dark); border-color: var(--teal-light); }
.modal-header h2 { margin: 0 0 24px 0; font-size: 1.25rem; font-weight: 800; color: #1e293b; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 26px; }
@keyframes modal-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Delete-confirmation modal (centered, destructive) ── */
.delete-modal-overlay {
    position: fixed; inset: 0; z-index: 200; background: rgba(17, 24, 39, 0.45);
    backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px;
    opacity: 0; visibility: hidden; transition: opacity var(--t-md), visibility var(--t-md);
}
.delete-modal-overlay.is-open { opacity: 1; visibility: visible; }
.delete-modal {
    background: var(--card); border-radius: var(--radius-md); box-shadow: var(--shadow-xl);
    border: 1px solid var(--line); padding: 32px 28px 24px; max-width: 420px; width: 100%; text-align: center;
    transform: scale(0.94) translateY(10px); transition: transform var(--t-md);
}
.delete-modal-overlay.is-open .delete-modal { transform: scale(1) translateY(0); }
.delete-modal-icon {
    width: 54px; height: 54px; border-radius: 50%; background: #fff1f2; color: var(--red);
    display: flex; align-items: center; justify-content: center; margin: 0 auto 18px; flex-shrink: 0;
}
.delete-modal-title { font-size: 1.05rem; font-weight: 700; color: var(--ink); margin: 0 0 8px; }
.delete-modal-body { font-size: 0.875rem; color: var(--muted); margin: 0 0 26px; line-height: 1.6; }
.delete-modal-body strong { color: var(--ink-body); font-weight: 600; }
.delete-modal-actions { display: flex; gap: 10px; }
.delete-modal-actions .button { flex: 1; justify-content: center; }
.delete-modal-confirm { background: var(--red) !important; border-color: var(--red) !important; color: #fff !important; }
.delete-modal-confirm:hover { background: #9b1c1c !important; border-color: #9b1c1c !important; }

/* ── Scroll reveal (paired with app.js) ── */
.reveal { opacity: 0; transform: translateY(12px); transition: opacity 380ms ease, transform 380ms ease; }
.reveal.is-visible { opacity: 1; transform: none; }
