/* ── Reset ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --navy: #0f2b46;
    --navy-light: #1a3d5c;
    --navy-dark: #091e32;
    --accent: #1b4f7a;
    --bg: #ffffff;
    --bg-subtle: #f8f9fb;
    --border: #e2e5ea;
    --text: #1a1a1a;
    --text-muted: #5a6270;
    --text-light: #8a919c;
    --success: #0d7a3e;
    --success-bg: #edf8f2;
    --success-border: #b4e4ca;
    --error: #c0392b;
    --error-bg: #fdf0ee;
    --error-border: #f0c0b8;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.06), 0 2px 12px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.1);
}

body {
    font-family:
        "Inter",
        system-ui,
        -apple-system,
        sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

main {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
}

.container {
    max-width: 1200px;
    width: 100%;
}

.subtitle {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

/* ── Login page ──────────────────────────────────────────────────── */
.login {
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 8vh;
}
.login > .back-link {
    display: block;
    text-align: center;
    margin-top: 1.5rem;
}
.login button,
.unavailable button {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* ── Landing page ─────────────────────────────────────────────────── */
.landing {
    text-align: center;
    margin-top: 8vh;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}
.landing h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: -0.02em;
}
.landing .description {
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-size: 1.05rem;
}

/* ── Card ─────────────────────────────────────────────────────────── */
.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

/* ── Forms ─────────────────────────────────────────────────────────── */
label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 0.3rem;
    margin-top: 1rem;
}
label:first-child {
    margin-top: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(27, 79, 122, 0.1);
}

/* ── Buttons ──────────────────────────────────────────────────────── */
button {
    margin-top: 1rem;
    padding: 0.6rem 1.5rem;
    background: var(--navy);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
button:hover {
    background: var(--navy-light);
}
button:active {
    background: var(--navy-dark);
}

/* ── Status messages ──────────────────────────────────────────────── */
.error {
    color: var(--error);
}
.success {
    color: var(--success);
}
.hint {
    color: var(--text-light);
    font-size: 0.8rem;
}
.help {
    text-align: left;
    margin-top: 1.5rem;
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.7;
}
.help ol {
    padding-left: 1.25rem;
}
.help p strong {
    color: var(--text);
}
.auth-links {
    font-size: 0.88rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}
.auth-links a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.auth-links a:hover {
    text-decoration: underline;
}
.auth-link {
    margin-top: 1rem;
    font-size: 0.9rem;
}
.auth-link a {
    color: var(--accent);
}
.back-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.back-link:hover {
    text-decoration: underline;
}
.note {
    color: var(--text-light);
    font-size: 0.85rem;
    margin-top: 1rem;
}

/* ── Navigation ───────────────────────────────────────────────────── */
.nav-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}
.nav-bar a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

/* ── File grid ────────────────────────────────────────────────────── */
.file-grid {
    display: grid;
    grid-template-columns: 1fr 5rem 8rem 8rem auto;
    width: 100%;
    user-select: none;
}
.file-grid-header,
.file-row {
    display: contents;
}
.file-grid-header > div,
.file-row > div {
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}
.file-grid-header > div {
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--bg-subtle);
}
.file-grid-header > div a {
    color: var(--text-muted);
    text-decoration: none;
}
.file-grid-header > div a:hover {
    color: var(--navy);
}
.file-row {
    cursor: pointer;
}
.file-row > div {
    transition: background 0.1s;
    font-size: 0.92rem;
}
.file-row:hover > div {
    background: var(--bg-subtle);
}
.file-row.selected > div {
    background: #e8eef5;
}
.file-row.selected:hover > div {
    background: #dce4ee;
}
.file-row > .file-actions {
    text-align: center;
}
.file-actions a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}
.file-actions a:hover {
    background: #e8eef5;
}

/* ── File toolbar ─────────────────────────────────────────────────── */
.file-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.file-toolbar input[type="search"] {
    flex: 1;
    min-width: 0;
}
.btn-toolbar {
    margin-top: 0;
    padding: 0.5rem 1rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Share dialog ─────────────────────────────────────────────────── */
.share-dialog {
    border: none;
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    max-width: 440px;
    width: 90%;
    margin: auto;
}
.share-dialog::backdrop {
    background: rgba(0, 0, 0, 0.35);
}
.share-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}
.share-header h3 {
    margin-bottom: 0;
}
.btn-close {
    background: none;
    color: var(--text-light);
    font-size: 1.4rem;
    padding: 0 0.4rem;
    margin: 0;
    line-height: 1;
    cursor: pointer;
}
.btn-close:hover {
    color: var(--text);
    background: none;
}
.share-count {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}
.share-permissions {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
.share-permissions legend {
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0 0.25rem;
}
.share-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}
.btn-preset {
    margin: 0;
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    background: #fff;
    color: var(--navy);
    border: 1px solid var(--navy);
    border-radius: 999px;
    cursor: pointer;
}
.btn-preset:hover {
    background: #f0f3f7;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: normal;
    margin: 0.25rem 0;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
    margin: 0;
}
.share-dialog label {
    margin-top: 0.75rem;
    margin-bottom: 0.2rem;
    font-size: 0.9rem;
}
.share-expires-row {
    display: flex;
    gap: 0.4rem;
}
.share-expires-row select {
    flex-shrink: 0;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95rem;
    background: #fff;
}
.share-expires-row input {
    flex: 1;
    min-width: 0;
}
.share-dialog input[type="datetime-local"],
.share-dialog input[type="number"] {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95rem;
}
.btn-generate {
    width: 100%;
    margin-top: 1rem;
}
.share-result {
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: 6px;
}
.share-result label {
    margin-top: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.share-url-row {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.25rem;
}
.share-url-row input {
    flex: 1;
    min-width: 0;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}
.btn-copy {
    margin: 0;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.share-dialog .error {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}
.share-dialog .success {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ── Token grid ───────────────────────────────────────────────────── */
.token-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 1fr 8rem 8rem 5rem 5rem auto;
    width: 100%;
    user-select: none;
}
.token-grid-header,
.token-grid .file-row {
    display: contents;
}
.token-grid-header > div,
.token-grid .file-row > div {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}
.token-grid-header > div {
    font-weight: 600;
}
.token-grid-header > div a {
    color: var(--accent);
    text-decoration: none;
}
.token-expired > div {
    background: var(--error-bg);
}
.token-revoked > div {
    background: var(--bg-subtle);
    color: var(--text-light);
}
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-active {
    background: #dcfce7;
    color: #166534;
}
.badge-expired {
    background: #fee2e2;
    color: #991b1b;
}
.badge-revoked {
    background: #e5e7eb;
    color: #6b7280;
}
.token-grid .file-row > div:first-child {
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}
.token-copy-url {
    font-size: 0.8rem;
    white-space: nowrap;
}

/* ── Renewal grid ────────────────────────────────────────────────── */
.renewal-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(
            0,
            1.5fr
        ) 8rem 5rem auto;
    width: 100%;
    user-select: none;
}
.renewal-grid-header,
.renewal-grid .file-row {
    display: contents;
}
.renewal-grid-header > div,
.renewal-grid .file-row > div {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}
.renewal-grid-header > div {
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--bg-subtle);
}
.renewal-grid-header > div a {
    color: var(--text-muted);
    text-decoration: none;
}
.renewal-grid-header > div a:hover {
    color: var(--navy);
}
.renewal-grid .file-row > div {
    font-size: 0.92rem;
}
.renewal-grid .file-row:hover > div {
    background: var(--bg-subtle);
}
.renewal-description {
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}
.badge-pending {
    background: #fef3c7;
    color: #92400e;
}
.badge-approved {
    background: #dcfce7;
    color: #166534;
}
.badge-denied {
    background: #fee2e2;
    color: #991b1b;
}

/* ── HTMX indicators ─────────────────────────────────────────────── */
.htmx-indicator {
    display: none;
}
.htmx-request .htmx-indicator {
    display: inline-block;
}
.htmx-request.htmx-indicator {
    display: inline-block;
}
.spinner::after {
    content: " ...";
}

/* ── Token file grid ──────────────────────────────────────────────── */
.token-file-grid {
    grid-template-columns: 1fr 5rem 10rem auto;
}

/* ── Tree: hidden rows when folder collapsed ──────────────────────── */
.file-row.tree-hidden {
    display: none;
}

/* ── Tree: synthetic folder rows ──────────────────────────────────── */
.folder-row {
    cursor: pointer;
}
.folder-row > div {
    background: var(--bg-subtle);
}
.folder-row:hover > div {
    background: #eef1f4;
}

/* ── Tree: toggle triangle ────────────────────────────────────────── */
.folder-toggle {
    cursor: pointer;
    user-select: none;
}
.folder-toggle.collapsed {
    transform: none;
}

/* ── Tree: indentation ────────────────────────────────────────────── */
.tree-indent {
    padding-left: calc(var(--tree-depth, 0) * 1.5rem) !important;
}

/* ── Fade-in for swapped content ──────────────────────────────────── */
.htmx-added {
    opacity: 0;
    animation: fade-in 0.3s ease-in forwards;
}
@keyframes fade-in {
    to {
        opacity: 1;
    }
}

/* ── Unavailable page ─────────────────────────────────────────────── */
.unavailable {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 8vh;
}
.unavailable h1 {
    color: var(--navy);
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}
.unavailable > p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}
.unavailable > .back-link {
    display: block;
    text-align: center;
    margin-top: 1.5rem;
}
.unavailable .help-text {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}
.unavailable .help-list {
    padding-left: 1.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.8;
    margin-bottom: 0.5rem;
}

/* ── Page header (title + right-aligned link) ─────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.page-header h1 {
    color: var(--navy);
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
}
.page-header-brand {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}
.page-header-brand .subtitle {
    margin: 0;
}

/* ── Feedback banner ──────────────────────────────────────────────── */
.feedback-success {
    padding: 0.6rem 1rem;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: 6px;
    color: var(--success);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.feedback-error {
    padding: 0.6rem 1rem;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 6px;
    color: var(--error);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
