/* Fancy Tabs System */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background: transparent;
}

.app-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
}

.app-header.no-border {
    border-bottom: none;
}

.app-header.compact {
    padding: 0.5rem 1.25rem;
}

.app-header.compact .logo-header.compact {
    gap: 0.75rem;
}

.app-header.compact .logo-header.compact .app-logo {
    width: 40px;
    height: 40px;
}

.app-header.compact .logo-header.compact h1 {
    font-size: 1.125rem;
    margin: 0;
}

.app-header .header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-header .session-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-header .session-info::before {
    content: none;
}

.app-header .icon-button {
    width: 2rem;
    height: 2rem;
}

.app-header .logout-button {
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
}

/* Tabs Container */
.tabs-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Tabs Navigation - Clean minimal design */
.tabs-nav {
    display: flex;
    gap: 0.25rem;
    padding: 0 1.25rem;
    background: transparent;
    border-bottom: 1px solid var(--border-color);
}

.tabs-nav.no-border {
    border-bottom: none;
}

.tab-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: -1px;
}

.tab-button:hover {
    color: var(--text-primary);
}

.tab-button.active {
    color: var(--primary-light);
    border-bottom-color: var(--primary-color);
}

.tab-button svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

/* Tab Content */
.tabs-content {
    flex: 1;
    position: relative;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-panel {
    display: none;
    width: 100%;
}

.tab-panel.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow: auto;
}

/* Chat Section (when in tab) */
.tab-panel .chat-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
}

.tab-panel .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    min-height: 0;
}

/* Insights and Rules panels */
.tab-panel[data-panel="insights"],
.tab-panel[data-panel="rules"] {
    overflow-y: auto;
}

/* ===========================================
   IFRAME CONTAINER SYSTEM
   Generic styles for any tab panel with iframe
   =========================================== */

/* Any panel containing an iframe should not scroll itself */
.tab-panel:has(iframe).active {
    overflow: hidden;
}

/* Fallback for browsers without :has() support */
.tab-panel.iframe-panel.active {
    overflow: hidden;
}

/* Generic iframe container wrapper */
.iframe-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Loading state for iframe containers */
.iframe-container .loading-state {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.125rem;
    background: var(--background);
    z-index: 1;
}

/* All iframes in tab panels */
.tab-panel iframe {
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
    border: none !important;
    outline: none;
    background: var(--background);
    display: block;
}

/* ===========================================
   HABITS EMBEDDED (uses iframe-container)
   =========================================== */
.habits-embedded {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.habits-embedded .loading-state {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    color: var(--text-secondary);
    font-size: 1.125rem;
    z-index: 1;
}

/* Iframe visibility control */
#habits-iframe {
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
    border: none;
    display: block;
}

#habits-iframe.hidden {
    opacity: 0;
    pointer-events: none;
}

#habits-iframe.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Insights Panel */
.insights-panel {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.insights-panel h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

.insights-panel h2 .emoji-icon {
    display: inline-block;
    margin-right: 0.5rem;
    -webkit-text-fill-color: initial;
    color: initial;
}

.insights-panel .info-message {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

/* Rules Panel */
.rules-panel-main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.rules-panel-main h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 2rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

.rules-panel-main h2 .emoji-icon {
    display: inline-block;
    margin-right: 0.5rem;
    -webkit-text-fill-color: initial;
    color: initial;
}

.rules-panel-main .rules-section {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.rules-panel-main .rules-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.rules-panel-main .rules-section-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.rules-panel-main .rules-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.refresh-button-small {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
}

.refresh-button-small:hover {
    background: var(--surface-hover);
    color: var(--primary-light);
}

.rules-panel-main .rules-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rules-panel-main .rule-item {
    background: var(--background-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.875rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.5;
}

.rules-panel-main .no-rules {
    color: var(--text-muted);
    font-style: italic;
    padding: 0.5rem 0;
}

.rules-panel-main .refresh-button {
    width: 100%;
    padding: 0.875rem;
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-bottom: 2rem;
}

.rules-panel-main .refresh-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.rules-panel-main .info-panel {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.rules-panel-main .info-panel h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rules-panel-main .info-panel ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rules-panel-main .info-panel li {
    padding: 0.5rem 0;
    padding-left: 1.75rem;
    color: var(--text-secondary);
    line-height: 1.6;
    position: relative;
}

.rules-panel-main .info-panel li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--primary-light);
    font-weight: 600;
}

/* Rules subtitle */
.rules-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 1.5rem;
    margin-top: -1rem;
}

/* Rule items */
.rules-panel-main .rule-item .rule-text {
    flex: 1;
}

.rules-panel-main .rule-item .rule-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    flex-shrink: 0;
}

.rules-panel-main .rule-item:hover .rule-delete-btn {
    opacity: 1;
}

.rules-panel-main .rule-item .rule-delete-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* No rules container */
.no-rules-container {
    text-align: center;
    padding: 2rem 1rem;
}

.no-rules-container .no-rules-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.no-rules-container .no-rules {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    font-style: normal;
}

.no-rules-container .no-rules-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Example chips for rules */
.rules-examples {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.rules-examples h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.example-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.example-chips .chip {
    background: var(--background-light);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: default;
    transition: all var(--transition-base);
}

.example-chips .chip:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Tab badge for incomplete habits */
.tab-button .tab-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    background: #ef4444;
    border-radius: 50%;
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

/* Refresh button with icon */
.rules-panel-main .refresh-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.875rem;
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-bottom: 2rem;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header.compact {
        padding: 0.5rem 1rem;
    }

    .app-header.compact .logo-header.compact .app-logo {
        width: 32px;
        height: 32px;
    }

    .app-header.compact .logo-header.compact h1 {
        font-size: 1rem;
    }

    .tabs-nav {
        gap: 0;
        padding: 0 0.75rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs-nav::-webkit-scrollbar {
        display: none;
    }

    .tab-button {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
        white-space: nowrap;
        gap: 0.375rem;
    }

    .tab-button span {
        display: none;
    }

    .tab-button svg {
        width: 20px;
        height: 20px;
    }

    .insights-panel,
    .rules-panel-main {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .tab-button {
        padding: 0.5rem 0.75rem;
    }
}

/* Smooth scrollbar */
.tab-panel::-webkit-scrollbar {
    width: 8px;
}

.tab-panel::-webkit-scrollbar-track {
    background: var(--background);
}

.tab-panel::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: 4px;
}

.tab-panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
