:root {
    --bg-color: #f5f5f7;
    --card-bg: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent-color: #0071e3;
    --accent-hover: #0077ed;
    --danger-color: #ff3b30;
    --border-color: #d2d2d7;
    --radius-l: 18px;
    --radius-m: 12px;
    --radius-s: 8px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 800px;
    margin: 40px auto;
    padding: 0 20px;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 40px;
}

.logo {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.5px;
}

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

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 14px;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-link:hover,
.nav-link.active {
    color: var(--accent-color);
}

.nav-link svg {
    width: 18px;
    height: 18px;
    fill: none;
    flex-shrink: 0;
}

h1 {
    font-size: 40px;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 10px;
    text-align: center;
}

h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    letter-spacing: -0.5px;
}

p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius-l);
    padding: 40px;
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 0 24px;
    /* Horizontal padding */
    height: 48px;
    /* Fixed height */
    border-radius: var(--radius-s);
    /* 8px */
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    line-height: normal;
}

.btn:hover {
    background-color: var(--accent-hover);
    transform: scale(1.02);
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    background-color: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background-color: #e5e5e7;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: #d2d2d7;
}

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

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

input[type="text"],
input[type="password"],
input[type="file"] {
    width: 100%;
    padding: 16px;
    border-radius: var(--radius-m);
    border: 1px solid var(--border-color);
    font-size: 17px;
    background-color: transparent;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    margin-bottom: 20px;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
}

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

/* Table Styles */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 10px;
}

th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px;
    border-bottom: 1px solid #e5e5e7;
    font-size: 15px;
}

tr:last-child td {
    border-bottom: none;
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 20px;
}

.flash-message {
    padding: 15px;
    border-radius: var(--radius-m);
    background-color: #fffae5;
    color: #b25b00;
    margin-bottom: 10px;
    font-size: 14px;
}

/* Loaders */
.loader {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading {
    display: none;
    text-align: center;
    padding: 40px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 15% auto;
    padding: 30px;
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 450px;
    position: relative;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close {
    color: var(--text-secondary);
    float: right;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.close:hover {
    color: var(--text-primary);
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .container {
        margin: 20px auto;
        padding: 0 16px;
    }

    .navbar {
        flex-direction: column;
        gap: 20px;
        padding: 15px 0;
    }

    .nav-items {
        width: 100%;
        justify-content: center;
        gap: 18px;
    }

    .nav-label {
        display: none;
    }

    .card {
        padding: 24px;
        border-radius: var(--radius-m);
    }

    h1 {
        font-size: 28px;
    }

    input[type="text"],
    input[type="password"],
    .btn {
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    th,
    td {
        padding: 10px;
        font-size: 14px;
    }

    .modal-content {
        margin: 30% auto;
        width: 85%;
    }
}

/* Help Modal Styles */
details {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-s);
    margin-bottom: 10px;
    overflow: hidden;
}

summary {
    background-color: #f9f9f9;
    padding: 15px;
    cursor: pointer;
    font-weight: 500;
    list-style: none;
    position: relative;
}

summary::-webkit-details-marker {
    display: none;
}

summary::after {
    content: '+';
    position: absolute;
    right: 15px;
    font-weight: bold;
    color: var(--text-secondary);
}

details[open] summary::after {
    content: '-';
}

.details-content {
    padding: 15px;
    background-color: white;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.details-content p {
    margin-bottom: 10px;
}

.details-content p:last-child {
    margin-bottom: 0;
}

code {
    background-color: #f6f8fa;
    border-radius: 6px;
    padding: 0.2em 0.4em;
    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 85%;
    color: #24292f;
    border: 1px solid rgba(27, 31, 36, 0.15);
}

/* Segmented Control Styles */
.segmented-control {
    background: #e5e5e7;
    padding: 4px;
    border-radius: 9px;
    display: inline-flex;
    position: relative;
    align-items: center;
    user-select: none;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    padding: 8px 24px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    /* Regular weight by default */
    margin: 0;
    transition: all 0.2s ease;
    position: relative;
    z-index: 2;
    /* Above background */
    color: #1d1d1f;
}

.selection-bg {
    position: absolute;
    background: white;
    border-radius: 7px;
    height: calc(100% - 8px);
    top: 4px;
    transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 1;
    pointer-events: none;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.setting-label {
    font-weight: 500;
    font-size: 15px;
}

@media (max-width: 600px) {
    .card {
        padding: 30px 20px !important;
    }

    .upload-form h1 {
        font-size: 24px;
    }

    .header-container {
        display: none !important;
    }

    /* Mobile Buttons on same line */
    /* Mobile Buttons on same line */
    .mobile-buttons-row {
        display: flex;
        /* Remove !important so style attribute can override */
        flex-direction: row !important;
        justify-content: center !important;
        gap: 10px !important;
        flex-wrap: nowrap !important;
    }

    /* Target only the buttons/labels, NOT the hidden input */
    .mobile-buttons-row>.btn {
        flex: 1 1 50% !important;
        /* Equal width */
        padding: 0 !important;
        /* Reset padding, use flex centering */
        height: 48px !important;
        /* Fixed height for consistency */
        font-size: 14px !important;
        margin: 0 !important;
        white-space: nowrap !important;
        display: inline-flex !important;
        justify-content: center !important;
        align-items: center !important;
        box-sizing: border-box !important;
        border-radius: 8px !important;
        /* Ensure styling matches */
    }

    /* Ensure input remains hidden */
    .mobile-buttons-row>input {
        display: none !important;
    }



    .segmented-control label {
        padding: 8px 16px;
        font-size: 13px;
    }

    .settings-grid {
        margin-bottom: 20px !important;
    }

    div[style*="margin-bottom: 40px"] {
        margin-bottom: 20px !important;
    }
}

/* Global override for these specific buttons to match requested style on Desktop too */
.mobile-buttons-row .btn {
    height: 48px !important;
    font-size: 14px !important;
    white-space: nowrap !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
    box-sizing: border-box !important;
    border-radius: 8px !important;
    padding: 0 20px !important;
    /* Minimal padding for desktop, flexible width */
}

/* On desktop, we want to allow them to be natural width or fixed? 
    User said "same style... just as they are in Mobile view".
    In mobile view they are 50% width. On desktop that might be huge.
    Let's stick to the height/shape but let width be auto or min-width.
*/
@media (min-width: 601px) {
    .mobile-buttons-row {
        gap: 15px !important;
    }

    .mobile-buttons-row .btn {
        min-width: 140px;
        /* Standard width on desktop */
        flex: 1 !important;
        /* Force equal width */
    }

    /* Constrain width to match the 2-button row (140+140+15 = 295px) */
    .desktop-aligned {
        max-width: 295px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        width: 100% !important;
        display: flex;
        /* Ensure flex behavior for controls */
        justify-content: center;
    }

    /* Submit button specific to centering */
    button.desktop-aligned {
        display: block;
        /* If it's just a button */
    }
}

@keyframes blink {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }

    100% {
        opacity: 1;
    }
}

/* ===== DRAG AND DROP ===== */
.upload-card {
    border: 2px solid transparent;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.upload-card.drag-over {
    border: 2px dashed var(--accent-color);
    background-color: rgba(0, 113, 227, 0.04);
}

/* ===== DARK MODE ===== */

/* Activated by system preference (unless user explicitly chose light) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-color: #1c1c1e;
        --card-bg: #2c2c2e;
        --text-primary: #f5f5f7;
        --text-secondary: #aeaeb2;
        --border-color: #3a3a3c;
    }
    :root:not([data-theme="light"]) .btn-secondary {
        background-color: #3a3a3c;
        color: #f5f5f7;
    }
    :root:not([data-theme="light"]) .btn-secondary:hover {
        background-color: #48484a;
    }
    :root:not([data-theme="light"]) .segmented-control {
        background: #3a3a3c;
    }
    :root:not([data-theme="light"]) .selection-bg {
        background: #636366;
    }
    :root:not([data-theme="light"]) .segmented-control label {
        color: #f5f5f7;
    }
    :root:not([data-theme="light"]) input[type="text"],
    :root:not([data-theme="light"]) input[type="password"],
    :root:not([data-theme="light"]) textarea,
    :root:not([data-theme="light"]) select {
        background-color: #3a3a3c;
        color: #f5f5f7;
        border-color: #48484a;
    }
    :root:not([data-theme="light"]) summary {
        background-color: #3a3a3c;
        color: #f5f5f7;
    }
    :root:not([data-theme="light"]) .details-content {
        background-color: #2c2c2e;
    }
    :root:not([data-theme="light"]) .flash-message {
        background-color: rgba(255, 180, 0, 0.15);
        color: #ffa040;
    }
    :root:not([data-theme="light"]) code {
        background-color: #3a3a3c;
        color: #e5e5e7;
        border-color: #48484a;
    }
    :root:not([data-theme="light"]) .upload-card.drag-over {
        background-color: rgba(0, 113, 227, 0.1);
    }
}

/* Explicitly set to dark by user toggle */
[data-theme="dark"] {
    --bg-color: #1c1c1e;
    --card-bg: #2c2c2e;
    --text-primary: #f5f5f7;
    --text-secondary: #aeaeb2;
    --border-color: #3a3a3c;
}
[data-theme="dark"] .btn-secondary {
    background-color: #3a3a3c;
    color: #f5f5f7;
}
[data-theme="dark"] .btn-secondary:hover {
    background-color: #48484a;
}
[data-theme="dark"] .segmented-control {
    background: #3a3a3c;
}
[data-theme="dark"] .selection-bg {
    background: #636366;
}
[data-theme="dark"] .segmented-control label {
    color: #f5f5f7;
}
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] textarea,
[data-theme="dark"] select {
    background-color: #3a3a3c;
    color: #f5f5f7;
    border-color: #48484a;
}
[data-theme="dark"] summary {
    background-color: #3a3a3c;
    color: #f5f5f7;
}
[data-theme="dark"] .details-content {
    background-color: #2c2c2e;
}
[data-theme="dark"] .flash-message {
    background-color: rgba(255, 180, 0, 0.15);
    color: #ffa040;
}
[data-theme="dark"] code {
    background-color: #3a3a3c;
    color: #e5e5e7;
    border-color: #48484a;
}
[data-theme="dark"] .upload-card.drag-over {
    background-color: rgba(0, 113, 227, 0.1);
}
