:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1a1a2e);
    --hint: var(--tg-theme-hint-color, #999999);
    --link: var(--tg-theme-link-color, #6c5ce7);
    --btn: var(--tg-theme-button-color, #6c5ce7);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f5);
    --section-bg: var(--tg-theme-section-bg-color, #ffffff);
    --section-header: var(--tg-theme-section-header-text-color, #6c5ce7);
    --separator: var(--tg-theme-section-separator-color, #e8e8ed);
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #e17055;
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    overflow-x: hidden;
}

/* Screens */
.screen {
    display: none;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}
.screen.active {
    display: block;
}

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

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--section-bg);
    border-bottom: 1px solid var(--separator);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header h1 {
    font-size: 18px;
    font-weight: 600;
}
.header-actions {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn:active {
    transform: scale(0.97);
}
.btn-primary {
    background: var(--btn);
    color: var(--btn-text);
}
.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text);
}
.btn-ghost {
    background: transparent;
    color: var(--accent);
    padding: 8px 12px;
}
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    background: var(--secondary-bg);
    font-size: 18px;
}
.btn-full {
    width: 100%;
}
.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Cards */
.card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--separator);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.card-date {
    font-size: 13px;
    color: var(--hint);
}
.card-situation {
    font-size: 15px;
    line-height: 1.4;
    margin-bottom: 8px;
}
.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.card-tag {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    background: var(--secondary-bg);
    color: var(--hint);
}

/* Entry list */
.entry-list {
    list-style: none;
}
.entry-item {
    cursor: pointer;
    transition: background 0.15s;
}
.entry-item:active {
    background: var(--secondary-bg);
}
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--hint);
}
.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
}
.empty-state p {
    font-size: 15px;
    margin-bottom: 20px;
}

/* Form */
.form-section {
    margin-bottom: 20px;
}
.form-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--section-header);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-label .step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}
.textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 1px solid var(--separator);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--section-bg);
    color: var(--text);
    resize: vertical;
    line-height: 1.5;
}
.textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}
.textarea::placeholder {
    color: var(--hint);
}

/* Chips / Tags selector */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.chip {
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    border: 1.5px solid var(--separator);
    background: var(--section-bg);
    color: var(--text);
    transition: all 0.15s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.chip:active {
    transform: scale(0.95);
}
.chip.selected {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.chip .info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    font-size: 11px;
    margin-left: 4px;
    vertical-align: middle;
    cursor: pointer;
}
.chip:not(.selected) .info-btn {
    background: var(--secondary-bg);
}

/* AI suggest button */
.ai-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}
.btn-ai {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    background: linear-gradient(135deg, #a29bfe, #6c5ce7);
    color: #fff;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}
.btn-ai:active {
    transform: scale(0.95);
}
.btn-ai:disabled {
    opacity: 0.5;
}
.btn-ai .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* AI suggestions */
.ai-suggestions {
    margin-top: 8px;
    padding: 10px;
    background: linear-gradient(135deg, rgba(162, 155, 254, 0.08), rgba(108, 92, 231, 0.08));
    border-radius: var(--radius-sm);
    border: 1px solid rgba(108, 92, 231, 0.15);
}
.ai-suggestions .label {
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 6px;
}
.ai-suggestion-item {
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--section-bg);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid var(--separator);
}
.ai-suggestion-item:active {
    background: var(--secondary-bg);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: flex-end;
    justify-content: center;
    animation: fadeInBg 0.2s ease;
}
.modal-overlay.active {
    display: flex;
}
@keyframes fadeInBg {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal {
    background: var(--section-bg);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h2 {
    font-size: 18px;
}
.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--secondary-bg);
    border: none;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-body {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
}
.modal-body p {
    margin-bottom: 10px;
}
.modal-body ul {
    padding-left: 20px;
    margin-bottom: 10px;
}
.modal-body li {
    margin-bottom: 4px;
}

/* Entry view */
.view-section {
    margin-bottom: 16px;
}
.view-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--hint);
    margin-bottom: 4px;
}
.view-content {
    font-size: 15px;
    line-height: 1.5;
}
.view-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.view-chip {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    background: var(--secondary-bg);
}

.ai-comment-box {
    padding: 12px;
    background: linear-gradient(135deg, rgba(162, 155, 254, 0.1), rgba(108, 92, 231, 0.1));
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
    font-size: 14px;
    line-height: 1.5;
}

/* Nav bar */
.nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--section-bg);
    border-top: 1px solid var(--separator);
    display: flex;
    padding: 8px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 8px;
    z-index: 50;
}
.nav-bar .btn {
    flex: 1;
}

/* Stepper indicator */
.stepper {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    justify-content: center;
}
.stepper-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--separator);
    transition: all 0.2s;
}
.stepper-dot.active {
    background: var(--accent);
    width: 24px;
    border-radius: 4px;
}
.stepper-dot.done {
    background: var(--success);
}

/* Copy feedback */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2000;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--hint);
    border-radius: 2px;
}

/* Actions row in view */
.actions-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--separator);
}
