/* TextMetrics Pro v2.0 - Complete Stylesheet */

/* ==========================================
   CSS Variables
   ========================================== */
:root {
    --tm-primary: #6366f1;
    --tm-accent: #22d3ee;
    --tm-success: #10b981;
    --tm-warning: #f59e0b;
    --tm-danger: #ef4444;
    --tm-editor-height: 400px;
}

.tm-app[data-theme="dark"] {
    --bg1: #0f172a;
    --bg2: #1e293b;
    --bg3: #334155;
    --text: #f1f5f9;
    --text2: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --glass: rgba(30, 41, 59, 0.8);
}

.tm-app[data-theme="light"] {
    --bg1: #f8fafc;
    --bg2: #ffffff;
    --bg3: #f1f5f9;
    --text: #1e293b;
    --text2: #64748b;
    --border: rgba(0, 0, 0, 0.1);
    --glass: rgba(255, 255, 255, 0.9);
}

/* ==========================================
   Base Styles
   ========================================== */
.tm-app {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg1);
    color: var(--text);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.tm-app *,
.tm-app *::before,
.tm-app *::after {
    box-sizing: border-box;
}

/* ==========================================
   Header
   ========================================== */
.tm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}

.tm-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tm-icon {
    font-size: 24px;
}

.tm-title {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--tm-primary), var(--tm-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tm-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tm-mode-select {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg3);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

.tm-btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg3);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
}

.tm-btn-icon:hover {
    background: var(--tm-primary);
    border-color: var(--tm-primary);
}

/* ==========================================
   Sheet Tabs (Excel-like)
   ========================================== */
.tm-sheet-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 8px 16px;
    background: var(--bg1);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tm-sheet-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: var(--bg3);
    color: var(--text2);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    top: 1px;
}

.tm-sheet-tab:hover {
    background: var(--bg2);
    color: var(--text);
}

.tm-sheet-tab.active {
    background: var(--bg2);
    color: var(--tm-primary);
    border-color: var(--tm-primary);
    border-bottom: 1px solid var(--bg2);
    font-weight: 600;
}

.tm-sheet-tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--tm-primary);
    border-radius: 8px 8px 0 0;
}

.tm-sheet-add {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-left: 8px;
}

.tm-sheet-add:hover {
    border-color: var(--tm-success);
    color: var(--tm-success);
    background: rgba(16, 185, 129, 0.1);
}

/* Theme Toggle Button - HIGH VISIBILITY */
.tm-theme-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 2px solid #00d4ff;
    border-radius: 8px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: #00d4ff !important;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tm-theme-btn .tm-theme-icon {
    font-size: 16px;
}

.tm-theme-btn .tm-theme-text {
    color: #00d4ff;
}

.tm-theme-btn:hover {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
    color: #fff !important;
}

.tm-theme-btn:hover .tm-theme-text {
    color: #fff;
}

/* Light theme - theme button */
[data-theme="light"] .tm-theme-btn {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-color: #f59e0b;
    color: #f59e0b !important;
}

[data-theme="light"] .tm-theme-btn .tm-theme-text {
    color: #f59e0b;
}

[data-theme="light"] .tm-theme-btn:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #fff !important;
}

/* Alignment Icons - DISTINCT STYLING */
.tm-align-icon {
    font-size: 16px;
    color: #ffffff !important;
}

/* ==========================================
   Toolbar
   ========================================== */
.tm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}

.tm-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tm-toolbar-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg3);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    min-width: 80px;
}

.tm-toolbar-select:hover {
    border-color: var(--tm-primary);
}

.tm-toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

/* Toolbar Buttons - HIGH CONTRAST */
.tm-toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: 2px solid #9b59b6;
    border-radius: 6px;
    background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
    color: #ffffff !important;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: Georgia, serif;
}

.tm-toolbar-btn strong,
.tm-toolbar-btn em,
.tm-toolbar-btn u,
.tm-toolbar-btn s,
.tm-toolbar-btn .tm-icon {
    color: #ffffff !important;
    font-size: 15px;
}

.tm-toolbar-btn:hover {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
    border-color: #00d4ff;
    transform: translateY(-1px);
}

.tm-toolbar-btn.active {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
    border-color: #00d4ff;
}

/* Light theme toolbar adjustments */
[data-theme="light"] .tm-toolbar-btn {
    background: linear-gradient(135deg, #8e44ad 0%, #732d91 100%);
    border-color: #8e44ad;
    color: #ffffff !important;
}

[data-theme="light"] .tm-toolbar-btn:hover {
    background: linear-gradient(135deg, #0099cc 0%, #007399 100%);
    border-color: #0099cc;
}

.tm-color-picker {
    width: 36px;
    height: 36px;
    padding: 4px;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: var(--bg3);
    cursor: pointer;
}

.tm-color-picker:hover {
    border-color: var(--tm-primary);
}

/* ==========================================
   Main Editor Area
   ========================================== */
.tm-main {
    display: grid;
    grid-template-columns: 1fr 200px;
    min-height: var(--tm-editor-height);
}

.tm-editor-wrap {
    padding: 16px;
    background: var(--bg1);
}

.tm-editor {
    width: 100%;
    min-height: var(--tm-editor-height);
    padding: 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 16px;
    line-height: 1.6;
    outline: none;
    overflow-y: auto;
    resize: vertical;
}

.tm-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text2);
    opacity: 0.6;
}

.tm-editor:focus {
    border-color: var(--tm-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* ==========================================
   Stats Sidebar
   ========================================== */
.tm-stats-sidebar {
    padding: 16px;
    background: var(--bg2);
    border-left: 1px solid var(--border);
}

.tm-stats-sidebar h3 {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--text2);
}

.tm-stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 13px;
}

.tm-stat-item span {
    color: var(--text2);
}

.tm-stat-item strong {
    color: var(--tm-accent);
    font-weight: 600;
}

.tm-stat-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* ==========================================
   Context Panel
   ========================================== */
.tm-context {
    padding: 16px 20px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
}

.tm-context-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--tm-accent);
}

.tm-context-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.tm-context-card {
    padding: 16px;
    background: var(--bg3);
    border-radius: 10px;
    border: 1px solid var(--border);
}

.tm-context-card h4 {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--text2);
    font-weight: 500;
}

.tm-context-card .value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.tm-context-card .label {
    font-size: 12px;
    color: var(--text2);
}

/* Platform limits */
.tm-platform-bar {
    height: 6px;
    background: var(--bg1);
    border-radius: 3px;
    margin-top: 8px;
    overflow: hidden;
}

.tm-platform-fill {
    height: 100%;
    background: var(--tm-primary);
    border-radius: 3px;
    transition: width 0.3s, background 0.3s;
}

.tm-platform-fill.warning {
    background: var(--tm-warning);
}

.tm-platform-fill.danger {
    background: var(--tm-danger);
}

/* ==========================================
   Tool Tabs
   ========================================== */
.tm-tools {
    background: var(--bg2);
    border-top: 1px solid var(--border);
}

.tm-tabs {
    display: flex;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
}

.tm-tab {
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.tm-tab:hover {
    color: var(--text);
}

.tm-tab.active {
    color: var(--tm-primary);
}

.tm-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--tm-primary);
}

.tm-tab-panels {
    padding: 16px;
}

.tm-panel {
    display: none;
}

.tm-panel.active {
    display: block;
}

.tm-tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

.tm-tool-btn {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg3);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.tm-tool-btn:hover {
    background: var(--tm-primary);
    border-color: var(--tm-primary);
    color: white;
    transform: translateY(-2px);
}

/* ==========================================
   Results Panel
   ========================================== */
.tm-results {
    margin: 16px;
    padding: 16px;
    background: var(--bg3);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.tm-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.tm-results-header h4 {
    margin: 0;
    font-size: 14px;
    color: var(--tm-accent);
}

.tm-results-content {
    font-size: 14px;
    line-height: 1.6;
    max-height: 300px;
    overflow-y: auto;
}

.tm-keyword-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.tm-keyword-item:last-child {
    border-bottom: none;
}

/* ==========================================
   Toast
   ========================================== */
.tm-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--tm-primary);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: all 0.3s;
    z-index: 9999;
}

.tm-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
    .tm-main {
        grid-template-columns: 1fr;
    }

    .tm-stats-sidebar {
        border-left: none;
        border-top: 1px solid var(--border);
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .tm-stats-sidebar h3 {
        grid-column: 1 / -1;
    }

    .tm-stat-divider {
        display: none;
    }

    .tm-toolbar {
        gap: 2px;
        padding: 8px;
    }

    .tm-toolbar-divider {
        display: none;
    }

    .tm-tool-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tm-header {
        flex-direction: column;
        gap: 12px;
    }

    .tm-context-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==========================================
   SEO Content Sections
   ========================================== */
.tm-seo-content {
    padding: 40px 30px;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tm-seo-header {
    text-align: center;
    margin-bottom: 40px;
}

.tm-seo-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #6366f1, #22d3ee);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0 0 16px 0;
    line-height: 1.2;
}

.tm-seo-tagline {
    font-size: 1.1rem;
    color: #94a3b8;
    max-width: 700px;
    margin: 0 auto;
    line-height: 1.6;
}

.tm-seo-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-top: 30px;
}

.tm-seo-feature {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 24px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.tm-seo-feature:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.2);
}

.tm-seo-feature h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #f1f5f9;
    margin: 0 0 12px 0;
}

.tm-seo-feature p {
    font-size: 0.95rem;
    color: #94a3b8;
    margin: 0;
    line-height: 1.6;
}

.tm-seo-feature strong {
    color: #22d3ee;
}

/* Noscript Fallback */
.tm-noscript-content {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 30px;
    margin-top: 30px;
}

.tm-noscript-content h2 {
    color: #f1f5f9;
    margin: 0 0 16px 0;
}

.tm-noscript-content ul {
    color: #94a3b8;
    padding-left: 24px;
}

.tm-noscript-content li {
    margin-bottom: 8px;
}

.tm-noscript-content strong {
    color: #6366f1;
}

/* ==========================================
   FAQ Section
   ========================================== */
.tm-faq-section {
    padding: 50px 30px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
}

.tm-faq-section>h2 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #f1f5f9;
    text-align: center;
    margin: 0 0 40px 0;
}

.tm-faq-list {
    max-width: 900px;
    margin: 0 auto;
}

.tm-faq-item {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.tm-faq-item:hover {
    border-color: rgba(99, 102, 241, 0.4);
}

.tm-faq-item summary {
    padding: 20px 24px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tm-faq-item summary::-webkit-details-marker {
    display: none;
}

.tm-faq-item summary::after {
    content: "+";
    font-size: 1.5rem;
    font-weight: 300;
    color: #6366f1;
    transition: transform 0.2s;
}

.tm-faq-item[open] summary::after {
    content: "−";
}

.tm-faq-item summary h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: #f1f5f9;
    margin: 0;
    flex: 1;
}

.tm-faq-item>p {
    padding: 0 24px 20px;
    margin: 0;
    color: #94a3b8;
    line-height: 1.7;
    font-size: 0.95rem;
}

.tm-faq-item strong {
    color: #22d3ee;
}

/* ==========================================
   SEO Article Section
   ========================================== */
.tm-seo-article {
    padding: 50px 30px;
    background: #0f172a;
}

.tm-seo-article h2 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #f1f5f9;
    margin: 0 0 30px 0;
    text-align: center;
}

.tm-seo-article h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #f1f5f9;
    margin: 30px 0 12px 0;
}

.tm-seo-article p {
    color: #94a3b8;
    line-height: 1.7;
    margin: 0 0 16px 0;
}

.tm-seo-article strong {
    color: #22d3ee;
}

.tm-seo-article ul {
    color: #94a3b8;
    padding-left: 24px;
    margin: 0 0 20px 0;
}

.tm-seo-article li {
    margin-bottom: 8px;
    line-height: 1.6;
}

/* Platform Limits Table */
.tm-limit-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: rgba(30, 41, 59, 0.6);
    border-radius: 12px;
    overflow: hidden;
}

.tm-limit-table th,
.tm-limit-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tm-limit-table th {
    background: rgba(99, 102, 241, 0.2);
    color: #f1f5f9;
    font-weight: 600;
}

.tm-limit-table td {
    color: #94a3b8;
}

.tm-limit-table tr:last-child td {
    border-bottom: none;
}

.tm-limit-table tr:hover td {
    background: rgba(99, 102, 241, 0.1);
}

/* Light theme overrides for SEO sections */
.tm-app[data-theme="light"]+.tm-faq-section,
.tm-app[data-theme="light"]+.tm-seo-article {
    background: #f8fafc;
}

/* SEO Content Responsive */
@media (max-width: 768px) {
    .tm-seo-header h1 {
        font-size: 1.8rem;
    }

    .tm-seo-tagline {
        font-size: 1rem;
    }

    .tm-seo-features {
        grid-template-columns: 1fr;
    }

    .tm-faq-section {
        padding: 30px 20px;
    }

    .tm-faq-item summary {
        padding: 16px 18px;
    }

    .tm-faq-item summary h3 {
        font-size: 0.95rem;
    }

    .tm-seo-article {
        padding: 30px 20px;
    }

    .tm-limit-table {
        font-size: 0.85rem;
    }

    .tm-limit-table th,
    .tm-limit-table td {
        padding: 10px 12px;
    }
}

/* ==========================================
   Skip Link (Accessibility)
   ========================================== */
.tm-skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary, #6366f1);
    color: #fff;
    padding: 12px 24px;
    border-radius: 0 0 8px 8px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    z-index: 10000;
    transition: top 0.2s ease;
}

.tm-skip-link:focus {
    top: 0;
    outline: 2px solid #22d3ee;
    outline-offset: 2px;
}

/* ==========================================
   Small Phone Breakpoint (480px)
   ========================================== */
@media (max-width: 480px) {
    .tm-header {
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
    }

    .tm-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .tm-mode-select {
        font-size: 0.8rem;
        padding: 6px 8px;
    }

    .tm-sheet-tabs {
        gap: 2px;
        padding: 4px 8px;
    }

    .tm-sheet-tab {
        font-size: 0.75rem;
        padding: 6px 10px;
    }

    .tm-toolbar {
        gap: 4px;
        padding: 6px 8px;
    }

    .tm-toolbar-btn {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .tm-stats-sidebar {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 10px;
    }

    .tm-stat-item {
        padding: 6px;
    }

    .tm-tab {
        font-size: 0.75rem;
        padding: 8px 10px;
    }

    .tm-tool-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .tm-seo-header h1 {
        font-size: 1.4rem;
    }

    .tm-seo-tagline {
        font-size: 0.9rem;
    }

    .tm-seo-content {
        padding: 20px 15px;
    }

    .tm-faq-section {
        padding: 20px 15px;
    }

    .tm-seo-article {
        padding: 20px 15px;
    }

    .tm-faq-item summary h3 {
        font-size: 0.85rem;
    }

    .tm-limit-table {
        font-size: 0.8rem;
    }

    .tm-limit-table th,
    .tm-limit-table td {
        padding: 8px 10px;
    }
}