:root {
    color-scheme: light;

    /* Not uygulaması (style.css) ile hizalı; CaseToolsHub semantik isimleri korunur */
    --bg: #f3f0ff;
    --surface: #ffffff;
    --surface-muted: #f9f8ff;
    --surface-strong: #ede9fe;
    --text: #1a1a2e;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-tertiary: #9ca3af;
    --border: #eee9f5;
    --border-strong: #e0d8ee;

    --primary: #7c5cfc;
    --primary-hover: #6a4be0;
    --primary-soft: #ede9fe;
    --primary-light: #ede9fe;
    --primary-lighter: #f5f3ff;

    --info: #3b82f6;
    --info-hover: #2563eb;
    --success: #059669;
    --success-hover: #047857;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;

    --ring: rgba(124, 92, 252, 0.22);
    --shadow-sm: 0 1px 3px rgba(100, 70, 180, 0.04);
    --shadow: 0 4px 24px rgba(100, 70, 180, 0.07);

    --radius: 12px;
    --transition: 160ms ease;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;

    --fs-body: 12px;
    --fs-input: 14px;
}

html[data-theme="light"] {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0c0a14;
    --surface: #15121f;
    --surface-muted: #252135;
    --surface-strong: #2f2650;
    --text: #f0eef6;
    --text-primary: #f0eef6;
    --text-secondary: #aaa5bc;
    --text-muted: #8b8499;
    --text-tertiary: #7f788e;
    --border: #2a2538;
    --border-strong: #3d3555;

    --primary: #9b87ff;
    --primary-hover: #b09cff;
    --primary-soft: #2f2650;
    --primary-light: #2f2650;
    --primary-lighter: #241d3d;

    --info: #60a5fa;
    --info-hover: #3b82f6;
    --success: #34d399;
    --success-hover: #10b981;
    --danger: #f87171;
    --danger-soft: rgba(239, 68, 68, 0.14);
    --warning: #fcd34d;
    --warning-soft: rgba(251, 191, 36, 0.1);

    --ring: rgba(167, 139, 250, 0.22);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow: 0 4px 28px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 90%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background-color: var(--bg);
    font-family: var(--font);
    font-size: var(--fs-body);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
}

.min-h-screen {
    min-height: 100vh;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.flex-1 {
    flex: 1 1 auto;
}

.inline-flex {
    display: inline-flex;
}

.cth-container {
    width: min(100% - 32px, 1540px);
    margin: 0 auto;
}

.cth-theme-fab {
    position: fixed;
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    z-index: 50;
    min-height: 40px;
    padding: 10px 14px;
    border-radius: var(--radius, 12px);
    border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--fs-btn, 12px);
    font-weight: 650;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition:
        background var(--transition, 160ms ease),
        border-color var(--transition, 160ms ease),
        color var(--transition, 160ms ease);
}

.cth-theme-fab:hover {
    background: var(--primary-soft);
    border-color: color-mix(in srgb, var(--primary) 35%, transparent);
    color: var(--primary);
}

.cth-theme-fab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

.main-content {
    padding: 28px 0 48px;
}

.app-page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.app-page-copy {
    min-width: 0;
}

.app-page-kicker,
.toolbox-kicker {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 28px;
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 760;
    padding: 4px 10px;
}

.app-page-title {
    margin: 10px 0 0;
    color: var(--text);
    font-size: 2rem;
    font-weight: 820;
    letter-spacing: 0;
    line-height: 1.12;
}

.app-page-subtitle {
    max-width: 560px;
    margin: 8px 0 0;
    color: var(--text-secondary);
    font-size: 1rem;
}

.quick-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(86px, 1fr));
    gap: 8px;
}

.quick-metric {
    min-width: 86px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 76%, transparent);
    padding: 10px 12px;
    box-shadow: var(--shadow-sm);
}

.quick-metric strong,
.quick-metric span {
    display: block;
}

.quick-metric strong {
    color: var(--text);
    font-size: 1.05rem;
    line-height: 1.1;
}

.quick-metric span {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 680;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(286px, 332px) minmax(0, 1fr);
    align-items: start;
    gap: 20px;
}

.toolbar {
    position: sticky;
    top: 20px;
    align-self: start;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow);
    padding: 16px;
}

.toolbox-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 14px;
}

.toolbox-title {
    margin: 10px 0 0;
    color: var(--text);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.2;
}

.toolbar-grid {
    display: grid;
    grid-template-columns: 1fr;
}

.tool-group {
    border-top: 1px solid var(--border);
    padding: 15px 0;
}

.tool-group:first-child {
    border-top: 0;
    padding-top: 2px;
}

.tool-group:last-child {
    padding-bottom: 0;
}

.tool-group-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.tool-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 790;
}

.tool-group-title svg {
    flex: 0 0 auto;
    color: var(--primary);
}

.tool-group-subtitle {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.76rem;
}

.tool-group-toggle {
    display: none;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.tool-group-toggle:hover {
    border-color: color-mix(in srgb, var(--primary) 32%, transparent);
    background: var(--primary-soft);
    color: var(--primary);
}

.tool-group-toggle svg {
    transition: transform var(--transition);
}

.tool-group.is-collapsed .tool-group-toggle svg {
    transform: rotate(-90deg);
}

.tool-group.is-collapsed .toolbar-buttons {
    display: none;
}

.toolbar-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.btn {
    display: inline-flex;
    min-width: 0;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 720;
    line-height: 1.2;
    padding: 8px 10px;
    text-align: center;
    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition),
        box-shadow var(--transition),
        transform var(--transition);
}

.btn:hover {
    border-color: color-mix(in srgb, var(--primary) 34%, transparent);
    background: var(--primary-soft);
    color: var(--primary);
}

.btn:active {
    transform: translateY(1px);
}

.btn:focus-visible,
.tool-group-toggle:focus-visible,
.text-area:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

.btn[disabled] {
    cursor: progress;
    opacity: 0.68;
}

.btn.is-loading {
    box-shadow: inset 0 -2px 0 rgba(255, 255, 255, 0.24);
}

.btn-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.btn-primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    border-color: var(--primary-hover);
    background: var(--primary-hover);
    color: #ffffff;
}

.btn-success {
    border-color: var(--info);
    background: var(--info);
    color: #ffffff;
}

.btn-success:hover {
    border-color: var(--info-hover);
    background: var(--info-hover);
    color: #ffffff;
}

.btn-danger {
    border-color: rgba(220, 38, 38, 0.35);
    color: var(--danger);
}

.btn-danger:hover {
    border-color: rgba(220, 38, 38, 0.48);
    background: var(--danger-soft);
    color: var(--danger);
}

.btn-icon {
    width: 38px;
    min-height: 38px;
    padding: 0;
}

.btn-compact {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.76rem;
}

.editor-zone {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 16px;
}

.stats-bar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow-sm);
    padding: 10px;
}

.stat-item {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--surface-muted);
    padding: 10px 12px;
}

.stat-label {
    min-width: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 720;
    overflow-wrap: anywhere;
}

.stat-value {
    color: var(--primary);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    font-weight: 830;
}

.editor-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.editor-panel {
    display: flex;
    min-width: 0;
    min-height: 520px;
    overflow: hidden;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    min-height: 56px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-muted) 100%);
    padding: 10px 12px 10px 14px;
}

.panel-title {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.86rem;
    font-weight: 780;
}

.panel-title svg {
    flex: 0 0 auto;
    color: var(--primary);
}

.panel-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
}

.text-area {
    width: 100%;
    flex: 1 1 auto;
    min-height: 462px;
    resize: vertical;
    border: 0;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: max(var(--fs-input), 12px);
    line-height: 1.72;
    outline: none;
    padding: 18px;
}

.text-area::placeholder {
    color: var(--text-muted);
}

.text-area:focus {
    box-shadow: inset 0 0 0 2px var(--primary);
}

.output-area {
    background: var(--surface-muted);
}

.history-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    box-shadow: var(--shadow-sm);
    padding: 14px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.history-title {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.86rem;
    font-weight: 780;
}

.history-title svg {
    color: var(--primary);
}

.history-list {
    display: grid;
    list-style: none;
    gap: 6px;
    margin: 0;
    padding: 0;
}

.history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.82rem;
    padding: 9px 10px;
    transition: background var(--transition), color var(--transition);
}

.history-item:hover {
    background: var(--primary-soft);
    color: var(--text);
}

.history-action {
    min-width: 0;
    color: var(--primary);
    font-weight: 760;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-time {
    color: var(--text-muted);
    font-size: 0.74rem;
    font-variant-numeric: tabular-nums;
    font-weight: 650;
}

.history-empty {
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.84rem;
    padding: 16px;
    text-align: center;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 9999;
    max-width: min(420px, calc(100% - 32px));
    transform: translateX(-50%) translateY(90px);
    border: 1px solid color-mix(in srgb, var(--primary) 22%, transparent);
    border-radius: var(--radius);
    background: #1a1a2e;
    box-shadow: var(--shadow);
    color: #ffffff;
    font-size: 0.88rem;
    font-weight: 700;
    opacity: 0;
    padding: 12px 16px;
    pointer-events: none;
    text-align: center;
    transition: opacity 220ms ease, transform 220ms ease;
}

html[data-theme="dark"] .toast:not(.toast-success):not(.toast-warning) {
    background: var(--surface-strong);
    color: var(--text);
    border-color: var(--border-strong);
}

.toast.toast-success {
    background: var(--success);
}

.toast.toast-warning {
    background: var(--warning);
}

html[data-theme="dark"] .toast.toast-warning {
    color: #1a1a2e;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.text-area::-webkit-scrollbar {
    width: 10px;
}

.text-area::-webkit-scrollbar-track {
    background: transparent;
}

.text-area::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background: var(--border-strong);
    background-clip: padding-box;
}

::selection {
    background: var(--primary);
    color: #ffffff;
}

@media (max-width: 1180px) {
    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .toolbar {
        position: static;
    }

    .toolbar-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 18px;
    }

    .tool-group:nth-child(2) {
        border-top: 0;
        padding-top: 2px;
    }
}

@media (max-width: 900px) {
    .cth-container {
        width: min(100% - 24px, 1540px);
    }

    .app-page-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .quick-metrics {
        width: 100%;
    }

    .toolbar-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .tool-group:nth-child(2) {
        border-top: 1px solid var(--border);
        padding-top: 15px;
    }

    .tool-group-toggle {
        display: inline-flex;
    }

    .stats-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .editor-grid {
        grid-template-columns: 1fr;
    }

    .editor-panel {
        min-height: 360px;
    }

    .text-area {
        min-height: 300px;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 20px 0 36px;
    }

    .app-page-title {
        font-size: 1.55rem;
    }

    .app-page-subtitle {
        font-size: 0.94rem;
    }

    .toolbar,
    .history-panel,
    .stats-bar,
    .editor-panel {
        box-shadow: var(--shadow-sm);
    }

    .quick-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .quick-metric {
        min-width: 0;
        padding: 8px;
    }

    .quick-metric strong {
        font-size: 0.95rem;
    }

    .quick-metric span {
        font-size: 0.68rem;
    }

    .stats-bar {
        grid-template-columns: 1fr;
    }

    .stat-item {
        padding: 9px 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
