/**
 * TheoTown Save Editor - Minimalist UI
 * Clean, refined, and professional
 */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&display=swap');

:root {
    /* Neutral Palette */
    --bg-base: #fafafa;
    --bg-surface: #ffffff;
    --bg-subtle: #f4f4f5;
    --bg-muted: #e4e4e7;

    /* Text Colors */
    --text-primary: #18181b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;
    --text-inverse: #ffffff;

    /* Accent - Subtle Blue */
    --accent: #2563eb;
    --accent-light: #dbeafe;
    --accent-dark: #1d4ed8;

    /* Semantic */
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #ca8a04;
    --warning-light: #fef9c3;
    --error: #dc2626;
    --error-light: #fee2e2;

    /* Typography */
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', Monaco, monospace;

    /* Spacing Scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Borders */
    --border-color: #e4e4e7;
    --border-radius: 8px;
    --border-radius-sm: 4px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-base: #09090b;
        --bg-surface: #18181b;
        --bg-subtle: #27272a;
        --bg-muted: #3f3f46;

        --text-primary: #fafafa;
        --text-secondary: #a1a1aa;
        --text-muted: #71717a;

        --accent-light: #1e3a5f;

        --border-color: #27272a;

        --success-light: #14532d;
        --warning-light: #422006;
        --error-light: #450a0a;
    }
}

/* ================== RESET & BASE ================== */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ================== LAYOUT ================== */

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-5);
}

/* ================== HEADER ================== */

header {
    text-align: center;
    margin-bottom: var(--space-10);
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
    letter-spacing: -0.02em;
}

.version {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* ================== MESSAGES ================== */

#error,
#success,
#changesIndicator {
    font-size: 0.875rem;
    font-weight: 500;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--border-radius-sm);
    margin-bottom: var(--space-4);
    display: none;
}

#error {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid var(--error);
}

#success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success);
}

#success.warning {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid var(--warning);
}

#changesIndicator {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid var(--warning);
}

/* ================== LOADER ================== */

#loader {
    display: none;
    flex-direction: column;
    align-items: center;
    padding: var(--space-12);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#loader p {
    margin-top: var(--space-4);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ================== DROP ZONE ================== */

#dropZone {
    background: var(--bg-surface);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--space-12) var(--space-6);
    text-align: center;
    transition: all var(--transition-base);
    cursor: pointer;
}

#dropZone:hover {
    border-color: var(--accent);
    background: var(--bg-subtle);
}

#dropZone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}

#dropZone h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

#dropZone p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-5);
}

#dropZone small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

input[type="file"] {
    display: none;
}

.file-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: var(--accent);
    color: var(--text-inverse);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.file-label:hover {
    background: var(--accent-dark);
}

/* ================== EDITOR ================== */

#editor {
    display: none;
}

/* ================== PANELS ================== */

.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: var(--space-5);
    overflow: hidden;
}

.panel h2 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-subtle);
}

.panel-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-subtle);
    margin-top: -1px;
    border-bottom: 1px solid var(--border-color);
}

/* ================== INFO GRID ================== */

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1px;
    background: var(--border-color);
}

.info-item {
    background: var(--bg-surface);
    padding: var(--space-4);
}

.info-item label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-1);
}

.info-item span {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ================== EDIT TABLE ================== */

.edit-table {
    width: 100%;
    border-collapse: collapse;
}

.edit-table thead {
    display: none;
}

.edit-table tr {
    border-bottom: 1px solid var(--border-color);
}

.edit-table tr:last-child {
    border-bottom: none;
}

.edit-table td {
    padding: var(--space-4);
    vertical-align: middle;
    font-size: 0.875rem;
}

.edit-table td:first-child {
    font-weight: 500;
    color: var(--text-primary);
    width: 120px;
}

.edit-table td:nth-child(3) {
    width: 80px;
}

.edit-table td:last-child {
    width: 50px;
    text-align: right;
}

/* Inputs */
.edit-table input[type="number"],
.edit-table input[type="text"] {
    width: 100%;
    max-width: 300px;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.edit-table input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Precision warning for values exceeding MAX_SAFE_INTEGER */
.edit-table input.precision-warning {
    border-color: var(--warning);
    background: var(--warning-light);
}

.edit-table input.precision-warning:focus {
    border-color: var(--warning);
    box-shadow: 0 0 0 3px rgba(202, 138, 4, 0.2);
}

.edit-table input::placeholder {
    color: var(--text-muted);
}

/* Select */
.gamemode-select {
    padding: var(--space-2) var(--space-3);
    padding-right: var(--space-8);
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2371717a' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color var(--transition-fast);
}

.gamemode-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.gamemode-select option {
    background: var(--bg-surface);
}

/* Offset */
.offset {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* Status */
.status-on {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--success);
}

.status-on::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
}

.status-off {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* ================== BUTTONS ================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
}

.btn-warning {
    background: var(--warning);
    color: var(--text-inverse);
}

.btn-warning:hover {
    filter: brightness(0.9);
}

.btn-small {
    padding: var(--space-1) var(--space-3);
    font-size: 0.75rem;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ================== ACTIONS ================== */

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-4);
}

/* ================== STATUS INDICATORS ================== */

.validation-status,
.backup-status {
    font-size: 0.75rem;
    padding: var(--space-2) var(--space-4);
    display: none;
}

.validation-status.valid {
    display: block;
    background: var(--success-light);
    color: var(--success);
}

.validation-status.warning {
    display: block;
    background: var(--warning-light);
    color: var(--warning);
}

.validation-status.error {
    display: block;
    background: var(--error-light);
    color: var(--error);
}

.backup-status.active {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--bg-subtle);
    color: var(--text-secondary);
}

.backup-status .backup-icon {
    color: var(--success);
}

/* ================== TOOLTIP ================== */

.tooltip {
    position: relative;
    display: inline-flex;
    cursor: help;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.tooltip .tooltip-text {
    visibility: hidden;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: var(--text-primary);
    color: var(--bg-surface);
    padding: var(--space-2) var(--space-3);
    font-size: 0.6875rem;
    white-space: nowrap;
    border-radius: var(--border-radius-sm);
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 10;
}

.tooltip .tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 6px;
    border: 4px solid transparent;
    border-top-color: var(--text-primary);
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* ================== FOOTER ================== */

footer {
    text-align: center;
    margin-top: var(--space-10);
    padding: var(--space-5);
    font-size: 0.75rem;
    color: var(--text-muted);
}

footer p+p {
    margin-top: var(--space-2);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.05em;
}

/* ================== RESPONSIVE ================== */

@media (max-width: 640px) {
    .container {
        padding: var(--space-5) var(--space-4);
    }

    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .edit-table td:nth-child(3) {
        display: none;
    }

    .edit-table input,
    .gamemode-select {
        max-width: 100%;
    }

    .actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

/* ================== UTILITY ================== */

.readonly {
    color: var(--text-muted);
}

.history-count {
    font-size: 0.625rem;
    font-family: var(--font-mono);
    background: var(--accent);
    color: var(--text-inverse);
    padding: 1px 5px;
    border-radius: 10px;
    margin-left: var(--space-1);
}