:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface2: #243044;
    --border: #2d3f56;
    --text: #e8edf4;
    --text-muted: #8b9cb3;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --link: #60a5fa;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    word-wrap: break-word;
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
}

.container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.header {
    margin-bottom: 2rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    font-size: 2.5rem;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.logo p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.brand-credit {
    margin-top: 0.35rem;
    font-size: 0.85rem !important;
    color: var(--text-muted);
}

.brand-credit strong {
    color: var(--primary);
    letter-spacing: 0.04em;
}

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

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.desc {
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.tips-box {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.tips-box ul {
    margin: 0.5rem 0 0 1.25rem;
}

.sample-download {
    margin-top: 1rem;
    margin-bottom: 0;
}

.tips-box code {
    background: var(--surface2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--link);
}

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

.export-box {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(34, 197, 94, 0.2);
}

.export-box p {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

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

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="number"] {
    width: 100%;
    max-width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 1.25rem;
    cursor: pointer;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.dropzone-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

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

.link-btn {
    background: none;
    border: none;
    color: var(--link);
    cursor: pointer;
    text-decoration: underline;
    font-size: inherit;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--success);
    font-weight: 500;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, opacity 0.2s;
}

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

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

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

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

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

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
}

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

.preview h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.sheet-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.sheet-badge {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.sheet-badge.visible {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.sheet-badge.hidden {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.success-box {
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-top: 1.5rem;
}

.success-box h3 {
    color: var(--success);
    margin-bottom: 0.5rem;
}

.link-box {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.link-box input {
    flex: 1 1 200px;
    min-width: 0;
    max-width: 100%;
    padding: 0.65rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
}

.apps-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.app-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    gap: 1rem;
    flex-wrap: wrap;
}

.app-item-info {
    min-width: 0;
    flex: 1 1 180px;
}

.app-item-info h4 {
    font-size: 1rem;
    margin-bottom: 0.2rem;
    overflow-wrap: anywhere;
}

.app-item-info small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.app-item-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    max-width: 100%;
}

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

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

.hidden {
    display: none !important;
}

.footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 1rem 0;
}

.footer-credit {
    margin-top: 0.4rem;
}

.footer-credit strong {
    color: var(--primary);
    letter-spacing: 0.04em;
}

.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 1000;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Viewer styles */
.viewer-body {
    background: #f0f4f8;
    color: #1a2332;
}

.viewer-loading,
.viewer-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 1rem;
    padding: 2rem;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #d1d9e6;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.viewer-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.viewer-header {
    background: #1a2332;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.viewer-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    max-width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
}

.viewer-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 0;
    overflow-wrap: anywhere;
}

.viewer-hint {
    font-size: 0.8rem;
    color: #8b9cb3;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
}

.viewer-credit {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #93c5fd;
    opacity: 0.9;
}

.viewer-main {
    flex: 1;
    padding: 1.5rem;
    overflow: auto;
}

.sheet-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.excel-table {
    border-collapse: collapse;
    font-family: 'Calibri', 'Segoe UI', sans-serif;
    font-size: 11pt;
    min-width: 100%;
    width: max-content;
    max-width: none;
}

.excel-table td {
    border: 1px solid #d4d4d4;
    padding: 4px 8px;
    min-width: 64px;
    max-width: 280px;
    vertical-align: middle;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    position: relative;
}

.excel-table td.empty {
    background: #fafafa;
}

.excel-table td.has-link {
    cursor: pointer;
    color: #0563c1;
    text-decoration: underline;
}

.excel-table td.has-link:hover {
    background: #e8f0fe;
}

.excel-table td.has-input {
    padding: 2px 4px;
    background: #fffef5;
}

.cell-input {
    width: 100%;
    min-width: 120px;
    border: 1px solid #c9b458;
    border-radius: 4px;
    padding: 4px 8px;
    font-family: inherit;
    font-size: inherit;
    background: #fff;
    color: #1a2332;
}

.cell-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.password-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: #f0f4f8;
}

.password-card {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.password-card h2 {
    margin-bottom: 0.5rem;
    color: #1a2332;
}

.password-card p {
    color: #6b7c93;
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}

.password-card input[type="password"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d9e6;
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.password-card .btn {
    width: 100%;
}

.password-error {
    color: #ef4444;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.admin-gate {
    margin-top: 0.75rem;
}

.admin-login-form {
    max-width: 360px;
}

.admin-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}

.stats-section {
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.stat-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 0.85rem;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

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

.stats-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.85rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stats-recent-title {
    margin-top: 1.25rem;
    margin-bottom: 0.65rem;
    font-size: 1rem;
}

.stats-recent {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stats-recent-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 0.75rem 0.85rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.stats-recent-item.is-deleted {
    opacity: 0.65;
}

.stats-recent-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
}

.stats-recent-info small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.stats-recent-meta {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.stats-badge {
    display: inline-block;
    margin-top: 0.25rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stats-recent-item {
        flex-direction: column;
        gap: 0.35rem;
    }

    .stats-recent-meta {
        text-align: left;
    }
}

.excel-table td.merged-hidden {
    display: none;
}

.excel-table td.highlight {
    animation: highlight 1.5s ease;
}

@keyframes highlight {
    0%, 100% { background: transparent; }
    30% { background: #fff3cd; }
}

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

    .card {
        padding: 1.25rem;
    }

    .logo {
        align-items: flex-start;
    }

    .logo h1 {
        font-size: 1.35rem;
    }

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

    .viewer-header {
        padding: 0.75rem 1rem;
    }

    .viewer-main {
        padding: 0.75rem;
    }

    .viewer-hint {
        width: 100%;
    }

    .excel-table {
        font-size: 10pt;
    }

    .excel-table td {
        max-width: 180px;
        min-width: 48px;
        padding: 3px 6px;
    }
}
