/* Theme Variables */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-sidebar: #2d2d2d;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-sidebar: #ffffff;
    --text-sidebar-dim: #aaaaaa;
    --border-color: #dddddd;
    --accent: #0066cc;
    --accent-hover: #0055aa;
    --error-bg: #ffeeee;
    --error-text: #cc3333;
    --success-bg: #eeffee;
    --success-text: #33aa33;
}

[data-theme="dark"] {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-sidebar: #252526;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-sidebar: #ffffff;
    --text-sidebar-dim: #888888;
    --border-color: #444444;
    --accent: #4da6ff;
    --accent-hover: #3399ff;
    --error-bg: #3d2020;
    --error-text: #ff6b6b;
    --success-bg: #203d20;
    --success-text: #6bff6b;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
}

#app {
    height: 100%;
}

/* Loading Screen */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
    color: var(--text-secondary);
}

.spinner {
    width: 50px;
    height: 50px;
    animation: rotate 1s linear infinite;
}

.spinner circle {
    stroke: var(--accent);
    stroke-linecap: round;
    stroke-dasharray: 90, 150;
    stroke-dashoffset: 0;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate {
    100% { transform: rotate(360deg); }
}

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

/* App Container */
.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 250px;
    min-width: 250px;
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, min-width 0.3s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 60px;
    min-width: 60px;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-header h1 {
    opacity: 0;
    width: 0;
}

.sidebar-search {
    padding: 10px 15px;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-sidebar);
    font-size: 13px;
}

.sidebar-search input::placeholder {
    color: var(--text-sidebar-dim);
}

.sidebar-search input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
}

.sidebar.collapsed .sidebar-search {
    display: none;
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.icon {
    width: 20px;
    height: 20px;
}

.nav {
    flex: 1;
    padding: 10px 0;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 4px;
}

.nav-section-header {
    padding: 8px 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-sidebar-dim);
    opacity: 0.7;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.nav-section-header:hover {
    opacity: 1;
}

.nav-section-header .chevron {
    width: 14px;
    height: 14px;
    transition: transform 0.2s ease;
}

.nav-section.collapsed .nav-section-header .chevron {
    transform: rotate(-90deg);
}

.nav-section-items {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.nav-section.collapsed .nav-section-items {
    max-height: 0;
}

.sidebar.collapsed .nav-section-header {
    display: none;
}

.sidebar.collapsed .nav-section-items {
    max-height: none;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    color: var(--text-sidebar-dim);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-sidebar);
    border-left: 3px solid var(--accent);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    margin-right: 12px;
    flex-shrink: 0;
}

.sidebar.collapsed .nav-item span {
    display: none;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px;
}

.sidebar.collapsed .nav-item svg {
    margin-right: 0;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-sidebar-dim);
    background: none;
    border: none;
    width: 100%;
    padding: 0;
    font-size: inherit;
}

.theme-toggle:hover {
    color: var(--text-sidebar);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    flex-shrink: 0;
}

.sidebar.collapsed .theme-toggle span {
    display: none;
}

.sidebar.collapsed .theme-toggle {
    justify-content: center;
}

.sidebar.collapsed .sidebar-footer {
    padding: 15px;
}

.coffee-link {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-sidebar-dim);
    text-decoration: none;
    font-size: inherit;
}

.coffee-link:hover {
    color: #ffdd00;
}

.coffee-link svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    flex-shrink: 0;
}

.sidebar.collapsed .coffee-link span {
    display: none;
}

.sidebar.collapsed .coffee-link {
    justify-content: center;
}

.credits-link {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    color: var(--text-sidebar-dim);
    cursor: pointer;
    font-size: 12px;
    opacity: 0.7;
}

.credits-link:hover {
    opacity: 1;
}

.credits-link svg {
    width: 16px;
    height: 16px;
    min-width: 16px;
}

.sidebar.collapsed .credits-link span {
    display: none;
}

.sidebar.collapsed .credits-link {
    justify-content: center;
}

/* Credits Page Styles */
.credits-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.credit-item {
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.credit-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.credit-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.credit-name:hover {
    text-decoration: underline;
}

.credit-license {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    color: var(--text-secondary);
}

.credit-description {
    margin: 0;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
}

/* Main Content */
.main {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
}

.tool-container {
    max-width: 900px;
}

.tool-header {
    margin-bottom: 25px;
}

.tool-header h2 {
    font-size: 24px;
    margin-bottom: 8px;
}

.tool-header p {
    color: var(--text-secondary);
}

.card {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.input-group {
    margin-bottom: 15px;
}

.output-group {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

textarea,
input[type="text"] {
    width: 100%;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
    transition: border-color 0.2s;
}

textarea {
    height: 200px;
}

textarea:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

textarea[readonly] {
    background: var(--bg-secondary);
}

.button-row {
    display: flex;
    gap: 10px;
    margin: 15px 0;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    font-size: 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.message {
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
}

.message.error {
    background: var(--error-bg);
    color: var(--error-text);
}

.message.success {
    background: var(--success-bg);
    color: var(--success-text);
}

/* Blazor Error UI */
#blazor-error-ui {
    background: #ffeeee;
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 16px;
    position: fixed;
    right: 0;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 16px;
    top: 16px;
}

/* Cron Tool Styles */
.cron-input-row {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.cron-input-row input[type="text"] {
    flex: 1;
    min-width: 200px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    white-space: nowrap;
    font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}

.description-text {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
}

.next-runs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.next-runs-header h3 {
    margin: 0;
}

.run-count-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.run-count-selector label {
    margin: 0;
    font-weight: normal;
}

.run-count-selector select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.next-runs-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

.next-runs-list li {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.builder-subtitle {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.builder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.builder-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.builder-field label {
    font-weight: 600;
    margin: 0;
}

.builder-field select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.builder-custom {
    font-size: 13px !important;
    padding: 6px 8px !important;
}

.common-expressions {
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.common-expressions h4 {
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn-preset {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    font-size: 13px;
}

.btn-preset:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.reference-table-wrapper {
    overflow-x: auto;
}

.reference-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
}

.reference-table th,
.reference-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.reference-table th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.reference-table td {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.special-chars {
    color: var(--text-secondary);
    font-size: 14px;
}

.special-chars p {
    margin: 5px 0;
}

.card h3 {
    margin-bottom: 15px;
}

.card h4 {
    margin-bottom: 10px;
}

/* Text Replacer Styles */
.replacer-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.replacer-field {
    display: flex;
    flex-direction: column;
}

.replacer-field input {
    flex: 1;
}

.options-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.options-row .checkbox-label input:disabled + span {
    opacity: 0.5;
}

.quick-action-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.quick-action-row label {
    margin: 0;
    white-space: nowrap;
}

.separator-input {
    width: 80px !important;
    flex: 0 0 auto !important;
}

/* Text Statistics Styles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Image Metadata Styles */
.file-input {
    width: 100%;
    padding: 12px;
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}

.file-input:hover {
    border-color: var(--accent);
}

.file-info {
    margin-top: 10px;
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
}

.quick-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.quick-info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.quick-info-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.quick-info-value {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
}

.metadata-group {
    margin-bottom: 10px;
}

.metadata-group summary {
    cursor: pointer;
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-weight: 500;
}

.metadata-group summary:hover {
    background: var(--border-color);
}

.metadata-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.metadata-table tr:nth-child(even) {
    background: var(--bg-secondary);
}

.metadata-key {
    padding: 6px 10px;
    font-weight: 500;
    white-space: nowrap;
    width: 200px;
}

.metadata-value {
    padding: 6px 10px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    word-break: break-all;
}

.map-link {
    display: inline-flex;
    margin-left: 8px;
    color: var(--accent);
    vertical-align: middle;
}

.map-link:hover {
    color: var(--accent-hover);
}

/* Image Converter Styles */
.preview-container {
    margin-top: 15px;
    text-align: center;
}

.image-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.format-options {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.format-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.format-option button {
    min-width: 80px;
}

.format-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

.quality-slider {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.quality-slider label {
    display: block;
    margin-bottom: 8px;
}

.quality-slider input[type="range"] {
    width: 100%;
    max-width: 300px;
}

/* File Validator Styles */
.format-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.format-selector label {
    margin: 0;
}

.format-selector select {
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.validation-result {
    padding: 15px;
    border-radius: 8px;
}

.validation-result.valid {
    background: var(--success-bg);
    color: var(--success-text);
}

.validation-result.invalid {
    background: var(--error-bg);
    color: var(--error-text);
}

.result-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 600;
}

.error-list {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid currentColor;
    opacity: 0.3;
}

.validation-result .error-list {
    opacity: 1;
    border-top-color: rgba(0, 0, 0, 0.1);
}

.error-item {
    padding: 8px 0;
    font-size: 14px;
}

.error-item + .error-item {
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.error-location {
    display: inline-block;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    margin-right: 10px;
}

.error-message {
    word-break: break-word;
}
