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

:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --border: #2d3f56;
    --text: #e8edf4;
    --text-muted: #8b9cb3;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --error: #ef4444;
    --radius: 10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.auth-card h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

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

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-nav {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    justify-content: center;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-2);
}

.nav-link-active {
    color: var(--text);
    background: var(--surface-2);
}

.header-title {
    color: var(--text);
    text-decoration: none;
}

.header-title:hover {
    color: var(--accent);
}

header h1 {
    font-size: 1.4rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    font-size: 1.2rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.subsection-title {
    font-size: 1rem;
    margin: 1.25rem 0 0.75rem;
    color: var(--text);
}

.section-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.preset-form {
    margin-bottom: 0;
}

.create-preset-panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem 1.35rem 1.35rem;
    margin-bottom: 1.25rem;
}

.create-preset-panel .subsection-title {
    margin-top: 0;
}

.create-preset-panel.form-panel-below {
    margin-top: 1.5rem;
    margin-bottom: 0;
}

.list-filters {
    margin-bottom: 1rem;
}

.preset-form .btn-inline {
    width: auto;
    margin-top: 0.25rem;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
    width: auto;
    margin-top: 0;
    flex: 1;
    min-width: 180px;
    text-align: center;
}

.alert.hidden {
    display: none;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

input[type="file"] {
    padding: 0.5rem;
}

small {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: -0.75rem;
    margin-bottom: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem 1.25rem;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.radio-group {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    color: var(--text);
    font-size: 0.95rem;
}

.radio-label input {
    accent-color: var(--accent);
}

button,
.btn-primary,
.btn-secondary,
.btn-download {
    display: inline-block;
    padding: 0.65rem 1.25rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}

button,
.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
    margin-top: 0.5rem;
}

.btn-inline {
    width: auto;
    margin-top: 0;
}

button:hover,
.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-download {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.btn-download:hover {
    background: rgba(59, 130, 246, 0.15);
}

.btn-danger {
    background: transparent;
    color: #f87171;
    border: 1px solid #f87171;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.15);
}

.preset-actions,
.loc-actions,
.client-actions,
.custom-actions,
.file-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.queue-action-buttons {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.preset-actions .btn-download,
.preset-actions .btn-danger,
.preset-actions .btn-secondary,
.loc-actions .btn-download,
.loc-actions .btn-danger,
.loc-actions .btn-secondary,
.client-actions .btn-download,
.client-actions .btn-danger,
.client-actions .btn-secondary,
.custom-actions .btn-download,
.custom-actions .btn-danger,
.custom-actions .btn-secondary,
.file-actions .btn-download,
.file-actions .btn-danger {
    width: auto;
    margin-top: 0;
}

.loc-actions > .btn-download,
.loc-actions > .btn-danger,
.loc-actions > a.btn-download,
.client-actions > .btn-download,
.client-actions > .btn-danger,
.custom-actions > .btn-download,
.custom-actions > .btn-danger,
.custom-actions > a.btn-download,
.file-actions > .btn-download,
.file-actions > .btn-danger {
    min-width: 5.5rem;
    text-align: center;
    box-sizing: border-box;
}

.portal-action-group {
    display: inline-flex;
    gap: 0.3rem;
    width: 11rem;
    flex: 0 0 11rem;
}

.portal-action-group .btn-download {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.35rem 0.35rem;
    font-size: 0.78rem;
    line-height: 1.2;
    white-space: nowrap;
}

#presets-table input {
    margin-bottom: 0;
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
}

#presets-table tr.editing td {
    vertical-align: middle;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--error);
    color: #fca5a5;
}

.alert-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid var(--success);
    color: #86efac;
}

.alert-info {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: var(--text);
    line-height: 1.5;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.progress-panel {
    margin-top: 1.25rem;
    padding: 1rem 1.1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.progress-panel.hidden {
    display: none;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

#progress-percent {
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.progress-track {
    height: 10px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #60a5fa);
    border-radius: 999px;
    transition: width 0.15s ease-out;
}

.progress-bar.indeterminate {
    width: 40% !important;
    animation: progress-indeterminate 1.4s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

.progress-detail {
    margin-top: 0.6rem;
    margin-bottom: 0;
    color: var(--text-muted);
    font-size: 0.82rem;
}

button:disabled,
.btn-primary:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.location-use-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.queue-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.portal-page .portal-card {
    max-width: 32rem;
    text-align: left;
}

.portal-page .portal-card h1 {
    text-align: center;
}

.portal-page .portal-card .subtitle {
    text-align: center;
    margin-bottom: 1.25rem;
}

.portal-settings-summary {
    margin-bottom: 1.25rem;
}

.portal-page label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.portal-page input[type="text"],
.portal-page input[type="file"],
.portal-page input[type="date"],
.portal-page input[type="number"] {
    width: 100%;
}

.portal-file-hint {
    display: block;
    margin-top: 0.35rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.portal-page .btn-primary {
    width: 100%;
    margin-top: 1.25rem;
}

.portal-page .progress-panel {
    margin-top: 1rem;
}

.client-portal-card {
    max-width: 42rem;
}

.client-portal-heading {
    margin: 1.5rem 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.client-portal-table {
    margin-top: 0.5rem;
}

.client-portal-action {
    text-align: right;
    white-space: nowrap;
}

.client-portal-select-col {
    width: 2.5rem;
    text-align: center;
}

.client-portal-select-col input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.client-portal-step.hidden {
    display: none;
}

.client-portal-progress {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.client-portal-upload-title {
    margin: 0 0 1.25rem;
    font-size: 1.15rem;
    font-weight: 600;
}

.client-portal-complete-list {
    margin: 1rem 0 1.5rem;
    padding-left: 1.25rem;
    color: var(--text-primary);
}

.client-portal-complete-list li {
    margin-bottom: 0.35rem;
}

.location-settings-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.setting-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.setting-chip span {
    color: var(--text-muted);
    margin-right: 0.35rem;
}

.location-result {
    margin-top: 1.25rem;
}

.location-result .alert-success {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
}

.inline-subtitle {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0;
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
    margin-top: 1rem;
}

.location-use-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.queue-live-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: capitalize;
}

.status-pending {
    background: rgba(139, 156, 179, 0.2);
    color: var(--text-muted);
}

.status-processing {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.status-completed {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

.status-failed {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.queue-progress-wrap {
    min-width: 140px;
}

.queue-progress-track {
    height: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.queue-progress-bar {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

.queue-progress-bar.status-pending {
    background: var(--text-muted);
}

.queue-progress-bar.status-processing {
    background: linear-gradient(90deg, var(--accent), #60a5fa);
}

.queue-progress-bar.status-completed {
    background: var(--success);
}

.queue-progress-bar.status-failed {
    background: var(--error);
}

.job-progress-message {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.job-error {
    color: #fca5a5;
    font-size: 0.85rem;
    cursor: help;
}

.queue-row-highlight {
    animation: highlight-fade 3s ease-out;
    background: rgba(59, 130, 246, 0.08);
}

@keyframes highlight-fade {
    0% { background: rgba(59, 130, 246, 0.22); }
    100% { background: rgba(59, 130, 246, 0.08); }
}

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

.user-you-badge {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    vertical-align: middle;
}

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

body.modal-open {
    overflow: hidden;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    padding: 1.25rem;
}

.modal-panel-wide {
    max-width: 720px;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.35rem;
    width: auto;
    margin-top: 0;
}

.modal-close:hover {
    color: var(--text);
    background: transparent;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary {
    width: auto;
    margin-top: 0;
}

.rich-text-box {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
}

.rich-text-box:focus-within {
    border-color: var(--accent);
}

.rich-text-toolbar {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.25rem;
    padding: 0.45rem 0.5rem;
    background: var(--surface-2);
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    overflow-x: auto;
}

.rich-text-toolbar .toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 2rem;
    height: 2rem;
    margin-top: 0;
    padding: 0 0.5rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    flex: 0 0 auto;
}

.rich-text-toolbar .toolbar-btn-wide {
    min-width: auto;
    padding: 0 0.65rem;
    font-weight: 500;
    font-size: 0.82rem;
}

.rich-text-toolbar .toolbar-btn:hover {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.rich-text-toolbar .toolbar-btn:active,
.rich-text-toolbar .toolbar-btn:focus-visible {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}

.toolbar-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--border);
    margin: 0 0.15rem;
    flex: 0 0 auto;
}

.rich-text-editor {
    min-height: 300px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 1rem 1.1rem;
    background: var(--bg);
    border: none;
    border-radius: 0;
    line-height: 1.6;
    outline: none;
}

.rich-text-editor:focus {
    border-color: transparent;
}

.rich-text-editor ul,
.rich-text-editor ol {
    margin: 0.5rem 0 0.5rem 1.25rem;
}

.rich-text-editor a {
    color: var(--accent);
}

.btn-notes-saved {
    border-color: rgba(34, 197, 94, 0.45);
    color: #86efac;
}

@media (max-width: 600px) {
    main {
        padding: 1rem;
    }

    .auth-card {
        padding: 1.5rem;
    }
}
