:root {
    /* Fallback theme variables if loaded outside Telegram */
    --bg-color: var(--tg-theme-bg-color, #ffffff);
    --text-color: var(--tg-theme-text-color, #222222);
    --hint-color: var(--tg-theme-hint-color, #888888);
    --button-color: var(--tg-theme-button-color, #2481cc);
    --button-text-color: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg-color: var(--tg-theme-secondary-bg-color, #f4f4f5);
    
    --success-color: #34c759;
    --danger-color: #ff3b30;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --border-radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    padding: 12px 16px;
    font-size: 16px;
}

#app-container {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 24px);
}

/* Navigation Tabs styling */
.tab-bar {
    display: flex;
    background-color: var(--secondary-bg-color);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--hint-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background-color 0.2s, color 0.2s;
    width: auto; /* override default button block styling */
}

.tab-btn.active {
    background-color: var(--bg-color);
    color: var(--text-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.badge {
    background-color: var(--danger-color);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 700;
}

main {
    flex-grow: 1;
}

.view-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Horizontal Filter Pills styling */
.filters-container {
    overflow-x: auto;
    margin-bottom: 16px;
    padding-bottom: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.filters-container::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
}

.filter-pills {
    display: flex;
    gap: 8px;
    width: max-content;
    padding: 2px 4px;
}

.pill-btn {
    background-color: var(--secondary-bg-color);
    color: var(--hint-color);
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    width: auto;
}

.pill-btn.active {
    background-color: var(--button-color);
    color: var(--button-text-color);
}

/* Center states (loading, empty, error) */
.center-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--hint-color);
    min-height: 250px;
}

.center-content .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.center-content p {
    font-size: 16px;
    margin-bottom: 8px;
}

.center-content .hint {
    font-size: 13px;
    opacity: 0.8;
}

/* Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: var(--button-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 16px;
}

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

/* Task & Recording Lists */
#task-list, #recordings-list, .completed-task-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-item, .recording-card {
    background-color: var(--secondary-bg-color);
    padding: 16px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s, opacity 0.2s;
}

.task-item.fade-out, .recording-card.fade-out {
    opacity: 0;
    transform: scale(0.95);
}

.task-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-grow: 1;
    padding-right: 8px;
}

.task-checkbox-container {
    margin-top: 3px;
    position: relative;
    cursor: pointer;
}

/* Custom checkbox */
.task-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--hint-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, border-color 0.2s;
}

.task-checkbox::after {
    content: "✓";
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: none;
}

.task-checkbox-container:hover .task-checkbox {
    border-color: var(--button-color);
}

.task-checkbox.checked {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.task-checkbox.checked::after {
    display: block;
}

.task-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.task-desc {
    font-weight: 500;
    font-size: 15px;
    word-break: break-word;
}

.task-due {
    font-size: 12px;
    color: var(--hint-color);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Collapsible Completed Section */
.completed-section {
    margin-top: 24px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 16px;
}

.completed-toggle {
    background: none;
    border: none;
    color: var(--hint-color);
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    width: auto;
    padding: 6px 0;
    outline: none;
}

.chevron-icon {
    font-size: 10px;
    transition: transform 0.2s;
    display: inline-block;
}

.completed-toggle.open .chevron-icon {
    transform: rotate(90deg);
}

/* Completed Items style styling */
.completed-item {
    opacity: 0.65;
}

.completed-item .task-desc {
    text-decoration: line-through;
    color: var(--hint-color);
}

/* Recording Card details */
.recording-card {
    cursor: pointer;
}

.recording-card:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.recording-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
}

.recording-transcription {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.recording-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--hint-color);
}

.recording-badge {
    background-color: var(--button-color);
    color: white;
    padding: 1px 6px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 10px;
}

.chevron {
    color: var(--hint-color);
    font-size: 18px;
    padding-left: 8px;
    align-self: center;
}

/* Buttons Container */
.task-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Action Buttons */
.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--hint-color);
    font-size: 16px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

.action-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.delete-btn:hover {
    background-color: rgba(255, 59, 48, 0.1);
    color: var(--danger-color);
}

.edit-btn:hover {
    background-color: rgba(36, 129, 204, 0.1);
    color: var(--button-color);
}

/* VIEW 3: Recording Detail View styling */
.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.detail-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.back-btn {
    background: none;
    border: none;
    color: var(--button-color);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    width: auto;
    padding: 0;
}

.transcription-box {
    margin-bottom: 20px;
}

.transcription-box label, .drafts-section label {
    font-size: 13px;
    font-weight: 600;
    color: var(--hint-color);
    margin-bottom: 6px;
    display: block;
}

#detail-transcription {
    background-color: var(--secondary-bg-color);
    padding: 12px;
    border-radius: var(--border-radius);
    font-style: italic;
    font-size: 14px;
    color: var(--text-color);
    border-left: 4px solid var(--button-color);
}

.drafts-section {
    margin-bottom: 28px;
}

#draft-tasks-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.draft-item {
    background-color: var(--secondary-bg-color);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.draft-item.rejected {
    opacity: 0.6;
}

.draft-item.rejected .task-desc {
    text-decoration: line-through;
    color: var(--hint-color);
}

.validation-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: auto;
}

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

.btn-danger {
    background-color: rgba(255, 59, 48, 0.1);
    color: var(--danger-color);
}

.btn-danger:active {
    background-color: rgba(255, 59, 48, 0.2);
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--bg-color);
    width: 100%;
    max-width: 500px;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    padding: 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(0);
    transition: transform 0.3s ease-out;
}

.modal.hidden .modal-content {
    transform: translateY(100%);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.close-icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--hint-color);
    cursor: pointer;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--hint-color);
}

.form-group textarea,
.form-group input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background-color: var(--secondary-bg-color);
    color: var(--text-color);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group textarea:focus,
.form-group input[type="text"]:focus {
    border-color: var(--button-color);
}

/* Presets Grid */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.preset-btn {
    padding: 10px 6px;
    font-size: 13px;
    font-weight: 500;
    background-color: var(--secondary-bg-color);
    color: var(--text-color);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    text-align: center;
}

.preset-btn:hover {
    border-color: var(--button-color);
}

.preset-btn.active {
    background-color: var(--button-color);
    color: var(--button-text-color);
    border-color: var(--button-color);
}

/* NLP date parse items */
.parse-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--hint-color);
    margin-top: 4px;
}

.spinner-small {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: var(--button-color);
    animation: spin 0.8s linear infinite;
}

.parse-preview {
    font-size: 13px;
    color: var(--success-color);
    font-style: italic;
    margin-top: 4px;
}

/* Footer / Close Button */
footer {
    margin-top: 32px;
    padding-bottom: 16px;
}

button {
    width: 100%;
    padding: 14px;
    background-color: var(--button-color);
    color: var(--button-text-color);
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: opacity 0.2s;
}

button:active {
    opacity: 0.85;
}

#retry-btn {
    width: auto;
    padding: 8px 24px;
    margin-top: 16px;
}

/* Helper Utilities */
.hidden {
    display: none !important;
}
