:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --surface2: #f1f3f5;
    --surface3: #e5e7eb;
    --border: #e4e7ec;
    --border-focus: #818cf8;
    --text: #111827;
    --text-secondary: #4b5563;
    --text-dim: #9ca3af;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #eef2ff;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #10b981;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 7px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 680px;
    margin: 0 auto;
    padding: 16px 16px 80px;
}

/* ===== Header ===== */
header {
    margin-bottom: 24px;
    padding-top: 8px;
}

.logo-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #6366f1, #a78bfa);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.2em;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

header h1 {
    font-size: 1.35em;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.2;
}

.subtitle {
    color: var(--text-dim);
    font-size: 0.82em;
    font-weight: 400;
    margin: 0;
}

/* ===== Navigation (pill style) ===== */
nav {
    display: flex;
    gap: 3px;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.nav-btn {
    flex: 1;
    padding: 9px 8px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 0.8em;
    font-weight: 500;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
}

.nav-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.nav-btn:hover { color: var(--text-secondary); }
.nav-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    font-weight: 600;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card-header {
    padding: 18px 20px 0;
}

.card-header h2 {
    font-size: 1em;
    font-weight: 650;
    margin-bottom: 2px;
}

.card-body {
    padding: 16px 20px 20px;
}

.card-muted {
    background: var(--surface2);
    border-color: transparent;
}

.hero-card {
    text-align: center;
    border: 1px solid rgba(99, 102, 241, 0.15);
    background: linear-gradient(180deg, var(--accent-light), var(--surface));
}

.hero-card .card-body { padding: 28px 20px; }
.hero-icon { font-size: 2em; margin-bottom: 8px; }
.hero-card h2 { font-size: 1.15em; margin-bottom: 4px; }

/* ===== Tabs ===== */
.tab { display: none; }
.tab.active { display: block; animation: fadeUp 0.2s ease; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Forms ===== */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child { margin-bottom: 0; }

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 550;
    font-size: 0.82em;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.label-badge {
    font-size: 0.75em;
    font-weight: 500;
    color: var(--text-dim);
    background: var(--surface2);
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 4px;
    vertical-align: middle;
}

.hint {
    color: var(--text-dim);
    font-size: 0.8em;
    margin-bottom: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 10px 13px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 0.9em;
    font-family: inherit;
    transition: all var(--transition);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder, textarea::placeholder {
    color: var(--text-dim);
    font-weight: 400;
}

textarea { resize: vertical; min-height: 42px; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

/* ===== Buttons ===== */
.btn-primary {
    padding: 11px 22px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 1px 3px rgba(99, 102, 241, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 3px 12px rgba(99, 102, 241, 0.3);
    transform: translateY(-0.5px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-full { width: 100%; justify-content: center; }

.btn-generate {
    padding: 13px 22px;
    font-size: 0.95em;
    margin-top: 4px;
}

.btn-add {
    width: 100%;
    padding: 10px;
    background: var(--surface2);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
}

.btn-add:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-icon {
    padding: 7px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 0.78em;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
}

.btn-icon:hover { background: var(--surface3); color: var(--text); }
.btn-icon svg { width: 14px; height: 14px; }

.btn-outline {
    flex: 1;
    padding: 10px 14px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 0.84em;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
}

.btn-outline:hover { background: var(--surface2); color: var(--text); }
.btn-outline svg { width: 15px; height: 15px; }

.btn-outline-danger { color: var(--danger); border-color: #fecaca; }
.btn-outline-danger:hover { background: var(--danger-light); color: var(--danger); }

.data-actions {
    display: flex;
    gap: 8px;
}

.save-status {
    display: block;
    text-align: center;
    margin-top: 8px;
    font-size: 0.85em;
    color: var(--success);
    font-weight: 500;
}

/* ===== Sticky save ===== */
.sticky-save {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
    z-index: 10;
    margin-top: 8px;
}

/* ===== Entry blocks ===== */
.entry-block {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 10px;
    position: relative;
    transition: border-color var(--transition);
}

.entry-block:hover { border-color: var(--surface3); }

.entry-block .remove-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9em;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.entry-block .remove-btn:hover { background: var(--danger-light); color: var(--danger); }
.entry-block .form-group { margin-bottom: 10px; }

/* ===== Loading ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 14px;
    padding: 14px;
    background: var(--accent-light);
    border-radius: var(--radius-xs);
    color: var(--accent);
    font-weight: 500;
    font-size: 0.88em;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}

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

.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(3, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    33% { content: '.'; }
    66% { content: '..'; }
    100% { content: '...'; }
}

.hidden { display: none !important; }

/* ===== Output ===== */
.output-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.output-header-row h2 { margin: 0; }
.output-actions { display: flex; gap: 6px; }
.output-body { padding-top: 16px; }

.markdown-box {
    background: var(--surface2);
    border-radius: var(--radius-xs);
    padding: 18px;
    font-family: 'SF Mono', 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8em;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 65vh;
    overflow-y: auto;
    line-height: 1.7;
    color: var(--text-secondary);
}

.preview-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 28px;
    max-height: 65vh;
    overflow-y: auto;
    line-height: 1.6;
}

.preview-box h1 { font-size: 1.4em; margin-bottom: 2px; color: var(--text); letter-spacing: -0.02em; }
.preview-box h2 { font-size: 1.05em; margin-top: 20px; margin-bottom: 8px; color: var(--accent); border-bottom: 2px solid var(--accent-light); padding-bottom: 3px; font-weight: 650; }
.preview-box h3 { font-size: 0.92em; margin-top: 12px; color: var(--text-secondary); }
.preview-box ul { margin-left: 18px; margin-bottom: 8px; }
.preview-box li { margin-bottom: 3px; }
.preview-box p { margin-bottom: 6px; }
.preview-box strong { color: var(--text); }
.preview-box hr { border: none; border-top: 1.5px solid var(--border); margin: 16px 0; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .app { padding: 12px 10px 80px; }
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .card-header { padding: 14px 16px 0; }
    .card-body { padding: 12px 16px 16px; }
    .nav-btn { padding: 8px 6px; font-size: 0.78em; }
    .nav-btn svg { width: 13px; height: 13px; }
    .output-header-row { flex-direction: column; align-items: flex-start; }
    .output-actions { width: 100%; justify-content: flex-start; }
    .data-actions { flex-direction: column; }
    .preview-box { padding: 20px; }
    .sticky-save { padding: 12px 16px; border-radius: var(--radius-xs); }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== Selection ===== */
::selection { background: var(--accent-light); color: var(--accent-hover); }

/* ===== Usage Display ===== */
.usage-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    padding: 10px 16px;
    background: var(--accent-light);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-xs);
    font-size: 0.85em;
    font-weight: 500;
    color: var(--accent);
}

.usage-info svg {
    color: var(--success);
    flex-shrink: 0;
}

.usage-info.limit-reached {
    background: var(--danger-light);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.usage-info.limit-reached svg {
    color: var(--danger);
}

.usage-info a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.usage-info a:hover {
    text-decoration: underline;
}

/* ===== Upgrade Modal ===== */
.upgrade-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 0;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25em;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1.2em;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

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

.modal-body {
    padding: 24px;
    text-align: center;
}

.upgrade-icon {
    font-size: 3em;
    margin-bottom: 16px;
}

.modal-body p {
    margin-bottom: 16px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.upgrade-features {
    margin: 24px 0;
    text-align: left;
}

.upgrade-feature {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.upgrade-feature svg {
    color: var(--success);
    flex-shrink: 0;
}

.upgrade-price {
    margin: 24px 0;
    padding: 20px;
    background: var(--accent-light);
    border-radius: var(--radius-xs);
}

.upgrade-price .price {
    font-size: 2.5em;
    font-weight: 800;
    color: var(--accent);
}

.upgrade-price .period {
    color: var(--text-dim);
    font-size: 0.9em;
    margin-left: 4px;
}

.modal-actions {
    padding: 0 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
