:root {
    --bg-canvas: #f7f8fa;
    --bg-card: #ffffff;
    --bg-subtle: #f3f4f6;
    --border-main: #e2e5ea;
    --border-strong: #cbd2d9;
    --brand-primary: #2563eb;
    --brand-primary-hover: #1d4ed8;
    --brand-primary-active: #1e40af;
    --airtable-blue: #2563eb;
    --airtable-blue-hover: #1d4ed8;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    --radius-card: 8px;
    --radius-control: 6px;
    --radius-sm: 4px;

    --success-bg: #f0fdf4;
    --success-text: #15803d;
    --success-border: #bbf7d0;

    --danger-bg: #fef2f2;
    --danger-text: #b91c1c;
    --danger-border: #fecaca;

    --info-bg: #eff6ff;
    --info-text: #1d4ed8;
    --info-border: #bfdbfe;
}

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

body {
    background-color: var(--bg-canvas);
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 2rem 1rem;
}

/* Remove generic AI ambient glow */
.background-glow {
    display: none;
}

.app-container {
    width: 100%;
    max-width: 460px;
    z-index: 1;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
}

.logo .icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo h1 {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.badge-public {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 400;
}

/* Main Commercial SaaS Card Surface */
.glass-panel {
    background-color: var(--bg-card);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-card);
    padding: 2rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04),
                0 4px 16px rgba(15, 23, 42, 0.04);
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.section-subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

/* Forms */
.secure-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input {
    background-color: #ffffff;
    border: 1px solid var(--border-main);
    border-radius: var(--radius-control);
    padding: 0.6875rem 0.875rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    text-align: center;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.02);
}

input:hover {
    border-color: var(--border-strong);
}

input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

/* Passcode specific input styling */
.passcode-input-container input {
    font-size: 1.5rem;
    letter-spacing: 0.5rem;
    padding: 0.65rem 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-indent: 0.5rem;
    max-width: 220px;
    margin: 0 auto;
    display: block;
}

.input-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 0.35rem;
    text-align: center;
}

/* Buttons */
.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    padding: 0.6875rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: -0.005em;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}

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

.btn-primary {
    background-color: var(--brand-primary);
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.22);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--brand-primary-hover);
}

.btn-primary:active:not(:disabled) {
    background-color: var(--brand-primary-active);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #ffffff;
    border: 1px solid var(--border-main);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

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

.btn-loader {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    border-top-color: currentColor;
    animation: spin 0.7s linear infinite;
}

.btn-secondary .btn-loader {
    border-color: rgba(15, 23, 42, 0.15);
    border-top-color: var(--brand-primary);
}

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

/* Summary Card */
.file-summary-card {
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-control);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-bottom: 1.25rem;
}

.success-card {
    border-color: var(--border-main);
    background-color: var(--bg-canvas);
}

.file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background-color: #ffffff;
    border: 1px solid var(--border-main);
    border-radius: var(--radius-control);
    flex-shrink: 0;
}

.file-meta {
    overflow: hidden;
    text-align: left;
    flex: 1;
}

.file-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.15rem;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Alert Notification box */
.alert-box {
    margin-top: 1rem;
    padding: 0.6875rem 1rem;
    border-radius: var(--radius-control);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    animation: fadeIn 0.2s ease;
}

.alert-error {
    background-color: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger-border);
}

.alert-success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

/* =========================================================================
   Resumable Downloader Dashboard
   ========================================================================= */

.download-dashboard {
    background-color: var(--bg-canvas);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-control);
    padding: 1rem;
    margin-top: 1rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-variant-numeric: tabular-nums;
    animation: fadeIn 0.25s ease;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--border-main);
    padding-bottom: 0.75rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.progress-bar-container {
    height: 6px;
    background-color: #e2e8f0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--airtable-blue);
    border-radius: var(--radius-sm);
    width: 0%;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-bytes-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.segments-map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.segments-map-header span:last-child {
    color: var(--airtable-blue);
    font-variant-numeric: tabular-nums;
}

.download-segments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12px, 1fr));
    gap: 3px;
    max-height: 140px;
    overflow-y: auto;
    padding: 0.5rem;
    background-color: #ffffff;
    border: 1px solid var(--border-main);
    border-radius: var(--radius-sm);
}

.segment-block {
    aspect-ratio: 1;
    border-radius: 1px;
    transition: background-color 0.2s ease;
}

.segment-block-pending {
    background-color: #e2e8f0;
}

.segment-block-downloading {
    background-color: #93c5fd;
    animation: segmentPulse 1.2s infinite ease-in-out;
}

.segment-block-success {
    background-color: var(--airtable-blue);
}

@keyframes segmentPulse {
    0% { opacity: 0.45; }
    50% { opacity: 1; }
    100% { opacity: 0.45; }
}

/* Control buttons group */
.download-control-buttons {
    display: flex;
    gap: 0.625rem;
    width: 100%;
}

.download-control-buttons button, .download-control-buttons a {
    flex: 1;
}

/* Fallback Links styling */
.download-fallback {
    text-align: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--bg-subtle);
}

.fallback-link {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: color 0.15s ease;
}

.fallback-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* Animations & Helpers */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.phase-container {
    animation: fadeIn 0.2s ease;
}

.hidden {
    display: none !important;
}

/* =========================================================================
   SVG Icons
   ========================================================================= */
.svg-icon {
    width: 1.25em;
    height: 1.25em;
    vertical-align: middle;
    display: inline-block;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.logo-svg {
    width: 1.5rem;
    height: 1.5rem;
    stroke: var(--brand-primary);
}

.file-card-svg {
    width: 1.35rem;
    height: 1.35rem;
    stroke: var(--text-secondary);
}

.success-card .file-card-svg {
    stroke: var(--success-text);
}

.btn-svg-icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}
