/* Logged-in app design system for sinfultwink.
   Tokens match static/css/auth.css and the homepage aesthetic. */

:root {
    --bg: #fff;
    --text: #333;
    --heading: #000;
    --muted: #666;
    --faint: #999;
    --card: #f9f9f9;
    --card-hover: #f0f0f0;
    --border: #ddd;
    --border-light: #f0f0f0;
    --input-bg: #fff;
    --btn-bg: #000;
    --btn-text: #fff;
    /* Brand red for primary actions, shared with homepage.css / auth.css so the
       logged-in app and the marketing/auth surfaces agree on the CTA look. */
    --accent: #e11d48;
    --accent-2: #be123c;
    --on-accent: #fff;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success-bg: #d4edda;
    --success-text: #155724;
    --shadow: rgba(0, 0, 0, 0.05);
    --shadow-strong: rgba(0, 0, 0, 0.15);
    --focus-ring: rgba(0, 0, 0, 0.1);
    --nav-bg: rgba(255, 255, 255, 0.95);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0a0a0a;
        --text: #e0e0e0;
        --heading: #fff;
        --muted: #aaa;
        --faint: #777;
        --card: #1a1a1a;
        --card-hover: #222;
        --border: #444;
        --border-light: #222;
        --input-bg: #2a2a2a;
        --btn-bg: #fff;
        --btn-text: #000;
        --accent: #fb2c56;
        --accent-2: #e11d48;
        --on-accent: #fff;
        --success-bg: #1e4620;
        --success-text: #90ee90;
        --shadow: rgba(0, 0, 0, 0.3);
        --shadow-strong: rgba(255, 255, 255, 0.15);
        --focus-ring: rgba(255, 255, 255, 0.1);
        --nav-bg: rgba(10, 10, 10, 0.95);
    }
}

/* Explicit theme choice wins over the OS.
   theme.js sets data-theme on <html> from the user's saved preference
   (localStorage 'theme', mirrored from Profile.dark_mode_preference). These
   selectors have higher specificity than the plain :root above and the :root
   inside the prefers-color-scheme block (media queries add no specificity),
   so an explicit choice always overrides the device setting. The values here
   are duplicates of the two blocks above; keep the three in sync. */
:root[data-theme="light"] {
    --bg: #fff;
    --text: #333;
    --heading: #000;
    --muted: #666;
    --faint: #999;
    --card: #f9f9f9;
    --card-hover: #f0f0f0;
    --border: #ddd;
    --border-light: #f0f0f0;
    --input-bg: #fff;
    --btn-bg: #000;
    --btn-text: #fff;
    --accent: #e11d48;
    --accent-2: #be123c;
    --on-accent: #fff;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success-bg: #d4edda;
    --success-text: #155724;
    --shadow: rgba(0, 0, 0, 0.05);
    --shadow-strong: rgba(0, 0, 0, 0.15);
    --focus-ring: rgba(0, 0, 0, 0.1);
    --nav-bg: rgba(255, 255, 255, 0.95);
}

:root[data-theme="dark"] {
    --bg: #0a0a0a;
    --text: #e0e0e0;
    --heading: #fff;
    --muted: #aaa;
    --faint: #777;
    --card: #1a1a1a;
    --card-hover: #222;
    --border: #444;
    --border-light: #222;
    --input-bg: #2a2a2a;
    --btn-bg: #fff;
    --btn-text: #000;
    --accent: #fb2c56;
    --accent-2: #e11d48;
    --on-accent: #fff;
    --success-bg: #1e4620;
    --success-text: #90ee90;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(255, 255, 255, 0.15);
    --focus-ring: rgba(255, 255, 255, 0.1);
    --nav-bg: rgba(10, 10, 10, 0.95);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

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

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

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- Top navigation ---------- */

.app-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-light);
}

.app-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    /* Anchor for the mobile links dropdown, which is absolutely positioned. */
    position: relative;
}

.app-nav-logo {
    font-size: 20px;
    font-weight: 700;
    text-decoration: none;
    color: var(--heading);
    white-space: nowrap;
    transition: opacity 0.2s;
}

.app-nav-logo:hover {
    opacity: 0.8;
}

.app-nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
    /* min-width:0 lets the list shrink instead of forcing the bar wider than
       the viewport; overflow-x keeps any tight tablet-width overflow inside the
       list rather than scrolling the whole page. */
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.app-nav-link {
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    white-space: nowrap;
    transition: all 0.2s;
}

.app-nav-link:hover {
    color: var(--heading);
    background: var(--card);
}

.app-nav-link.active {
    color: var(--btn-text);
    background: var(--btn-bg);
}

.app-nav-logout {
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    margin-left: 8px;
}

.app-nav-logout:hover {
    color: var(--heading);
    border-color: var(--heading);
}

/* Right-side cluster: notification bell plus the mobile menu toggle. The
   toggle is hidden on wide screens and appears only in the responsive block. */
.app-nav-end {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.app-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s, border-color 0.2s;
}

.app-nav-toggle:hover {
    color: var(--heading);
    border-color: var(--heading);
}

.app-nav-toggle svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* ---------- Main layout ---------- */

.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 20px 60px;
    animation: fadeIn 0.2s ease;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--heading);
}

.page-subtitle {
    font-size: 14px;
    color: var(--muted);
}

/* ---------- Cards ---------- */

.card {
    background: var(--card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}

.card-clickable {
    cursor: pointer;
}

.card-clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-strong);
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--heading);
    margin-bottom: 12px;
}

.card-meta {
    font-size: 13px;
    color: var(--faint);
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-block;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-strong);
}

.btn-secondary {
    background: transparent;
    color: var(--heading);
    border: 1px solid var(--heading);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--btn-bg);
    color: var(--btn-text);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
    transform: translateY(-2px);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    display: block;
    width: 100%;
}

/* ---------- Forms ---------- */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select,
.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
    transition: all 0.2s;
}

.form-group textarea {
    resize: vertical;
    min-height: 90px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.form-control:focus {
    outline: none;
    border-color: var(--heading);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-group input:disabled,
.form-group textarea:disabled,
.form-group select:disabled,
.form-control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-hint {
    color: var(--faint);
    font-size: 13px;
    margin-top: 6px;
    display: block;
}

.error-message {
    color: var(--danger);
    font-size: 13px;
    margin-top: 6px;
    display: none;
    animation: slideIn 0.2s ease;
}

/* Toggled from JS via classList instead of inline style writes. */
.error-message.visible {
    display: block;
}

.success-message {
    background: var(--success-bg);
    color: var(--success-text);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: none;
    font-size: 14px;
    animation: slideIn 0.2s ease;
}

/* ---------- Loading indicator ---------- */

.loading {
    display: none;
    text-align: center;
    font-size: 14px;
    color: var(--muted);
    margin-top: 10px;
    animation: fadeIn 0.2s ease;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 6px;
    border: 2px solid var(--muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

/* ---------- List rows ---------- */

.list {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
}

.list-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
    color: inherit;
    text-decoration: none;
    transition: background 0.2s;
}

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

.list-row:hover {
    background: var(--card-hover);
}

.list-row-body {
    flex: 1;
    min-width: 0;
    /* Stack title over subtitle; without a column the two inline spans run
       together on one line and spill over the row's trailing controls. */
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.list-row-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-row-sub {
    font-size: 13px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-row-end {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    font-size: 13px;
    color: var(--faint);
}

/* ---------- Badges / pills ---------- */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--btn-bg);
    color: var(--btn-text);
    line-height: 1.6;
}

.badge-muted {
    background: var(--card-hover);
    color: var(--muted);
}

.badge-danger {
    background: var(--danger);
    color: #fff;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success-text);
}

/* ---------- Avatar ---------- */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--btn-bg);
    color: var(--btn-text);
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
    overflow: hidden;
    user-select: none;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 12px;
}

.avatar-lg {
    width: 72px;
    height: 72px;
    font-size: 28px;
}

/* ---------- Modal ---------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    animation: slideIn 0.2s ease;
}

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

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--heading);
}

.modal-close {
    font-family: inherit;
    font-size: 20px;
    line-height: 1;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    color: var(--heading);
    background: var(--card-hover);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ---------- Empty state ---------- */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty-state-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--heading);
    margin-bottom: 8px;
}

.empty-state-text {
    font-size: 14px;
    max-width: 380px;
    margin: 0 auto 20px;
}

/* ---------- Toast ---------- */

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: calc(100vw - 40px);
}

.toast {
    background: var(--btn-bg);
    color: var(--btn-text);
    padding: 12px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px var(--shadow-strong);
    animation: slideIn 0.2s ease;
    max-width: 360px;
}

.toast-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.toast-error {
    background: var(--danger);
    color: #fff;
}

.toast-out {
    opacity: 0;
    transition: opacity 0.2s;
}

/* ---------- Grid helpers ---------- */

.grid {
    display: grid;
    gap: 20px;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.grid-auto {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/* ---------- Utilities ---------- */

.hidden {
    display: none !important;
}

/* Off-screen but exposed to assistive tech; used for aria-live status regions
   (e.g. the notification unread announcer) and other screen-reader-only text. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--muted);
}

.text-faint {
    color: var(--faint);
}

.text-heading {
    color: var(--heading);
}

.text-small {
    font-size: 13px;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flex {
    display: flex;
    align-items: center;
    gap: 10px;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.flex-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-1 {
    flex: 1;
    min-width: 0;
}

.w-100 {
    width: 100%;
}

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
    /* Seven links plus logo/bell/logout do not fit on one row until ~960px,
       so collapse to the hamburger below that. Bar stays a single row: logo
       left, bell + menu toggle right; the link list drops into a dropdown so
       the nav can never be wider than the viewport. */
    .app-nav-inner {
        gap: 12px;
        padding: 12px 16px;
    }

    .app-nav-toggle {
        display: inline-flex;
    }

    .app-nav-links {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        margin: 0;
        padding: 8px 16px 12px;
        background: var(--nav-bg);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border-light);
        box-shadow: 0 10px 24px var(--shadow-strong);
        max-height: calc(100vh - 64px);
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-nav-links.is-open {
        display: flex;
    }

    .app-nav-link {
        padding: 10px 12px;
        border-radius: 8px;
    }

    .app-nav-logout {
        width: 100%;
        margin-left: 0;
        margin-top: 4px;
    }

    /* Keep the bell its natural size inside the right-side cluster (overrides
       the old full-width mobile rule in notifications.css). */
    .app-nav-end .notif {
        margin-left: 0;
    }

    .app-main {
        padding: 20px 16px 40px;
    }

    .page-title {
        font-size: 22px;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .modal {
        max-width: none;
    }
}

/* ---------- Accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--heading);
    outline-offset: 2px;
}

/* Brand accent: two-tone wordmark in the app nav */
.app-nav-logo-accent {
    color: var(--accent);
}
