/* ===== CSS Variables (Dark AI Theme) ===== */
:root {
    --primary-color: #00d4ff;
    --secondary-color: #6f42c1;
    --dark-bg: #0a0e27;
    --card-bg: #1a1f3a;
    --border-color: #3d4563;
    --text-primary: #e0e6ed;
    --text-secondary: #a8b3c1;
    --success-color: #00c896;
    --danger-color: #ff3333;
    --warning-color: #ffa500;
    --site-max-width: 860px;
    --navbar-max-width: 1320px;
    --navbar-height: 86px;
    --transition: all 0.3s ease;
}

/* ===== Global Styles ===== */
* {
    text-decoration: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.navbar-brand a {
    text-decoration: none;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-primary);
    background-color: var(--dark-bg);
}

body {
    display: flex;
    flex-direction: column;
    padding-top: var(--navbar-height);
}

/* ===== Navbar ===== */
.navbar {
    background: linear-gradient(135deg, #0f1530 0%, #1a1f3a 100%);
    border-bottom: 2px solid var(--primary-color);
    min-height: var(--navbar-height);
    padding: 0;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
}

.navbar-container {
    max-width: var(--navbar-max-width);
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: var(--navbar-height);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.navbar-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.version {
    background: var(--card-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    border: 1px solid var(--primary-color);
}

.tools-select {
    min-width: 185px;
    height: 42px;
    border: 1px solid rgba(0, 212, 255, 0.45);
    border-radius: 999px;
    background:
        linear-gradient(135deg, rgba(0, 212, 255, 0.12), rgba(111, 66, 193, 0.16)),
        rgba(10, 14, 39, 0.96);
    color: var(--text-primary);
    padding: 0 2.4rem 0 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    outline: none;
    box-shadow: 0 0 18px rgba(0, 212, 255, 0.12);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image:
        linear-gradient(135deg, rgba(0, 212, 255, 0.12), rgba(111, 66, 193, 0.16)),
        linear-gradient(45deg, transparent 50%, var(--primary-color) 50%),
        linear-gradient(135deg, var(--primary-color) 50%, transparent 50%);
    background-position:
        0 0,
        calc(100% - 18px) 17px,
        calc(100% - 12px) 17px;
    background-size:
        100% 100%,
        6px 6px,
        6px 6px;
    background-repeat: no-repeat;
    cursor: pointer;
    transition: var(--transition);
}

.tools-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.14), 0 0 22px rgba(0, 212, 255, 0.2);
}

.tools-select:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 24px rgba(0, 212, 255, 0.18);
}

.tools-select option {
    background: #1a1f3a;
    color: var(--text-primary);
}

/* ===== Container & Layout ===== */
.container {
    flex: 1;
    max-width: var(--site-max-width);
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
}

.content-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

/* ===== Ad Blocks ===== */
.ad-section {
    display: flex;
    justify-content: center;
}

.ad-section .adsbygoogle {
    width: 100%;
    max-width: 970px;
    margin: 0 auto;
}

/* ===== Header Section ===== */
.header-section {
    text-align: center;
    padding: 2rem;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(111, 66, 193, 0.1));
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 1rem;
}

.header-section h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
}

.header-section p {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* ===== Rules Section ===== */
.rules-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.rules-section h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.rules-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.75rem;
}

.rules-list li {
    padding: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    border-left: 3px solid var(--success-color);
    padding-left: 1rem;
}

/* ===== Main Content ===== */
.main-content {
    display: grid;
    gap: 2rem;
}

/* ===== Upload Section ===== */
.upload-section {
    background: var(--card-bg);
    border: 2px dashed var(--primary-color);
    border-radius: 12px;
    padding: 3rem;
    transition: var(--transition);
}

.upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.upload-header h3 {
    color: var(--primary-color);
    margin: 0;
    font-size: 1.1rem;
}

.file-count {
    background: var(--primary-color);
    color: var(--dark-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
}

.drag-drop-zone {
    text-align: center;
    cursor: pointer;
    padding: 2rem;
}

.drag-drop-zone.dragover {
    background: rgba(0, 212, 255, 0.1);
    transform: scale(1.02);
}

.drag-drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.upload-icon {
    width: 80px;
    height: 80px;
    color: var(--primary-color);
    opacity: 0.7;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.drag-drop-zone h3 {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.drag-drop-zone p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ===== Preview Section ===== */
.preview-section {
    margin-top: 2rem;
    padding: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.preview-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

.preview-image-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.preview-image-frame {
    position: relative;
    width: 100%;
    height: 320px;
    overflow: hidden;
}

.preview-counter {
    position: absolute;
    left: 50%;
    bottom: 0.75rem;
    transform: translateX(-50%);
    min-width: 84px;
    text-align: center;
    color: var(--primary-color);
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.35rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(10, 14, 39, 0.72);
    backdrop-filter: blur(4px);
    z-index: 1;
}

.preview-image {
    max-width: 100%;
    min-width: 420px;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: block;
    background: rgba(0, 0, 0, 0.25);
}

.preview-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(10, 14, 39, 0.72);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1;
    transition: var(--transition);
    backdrop-filter: blur(4px);
}

.preview-nav-btn i {
    font-size: 1rem;
    line-height: 1;
}

.preview-nav-btn:hover:not(:disabled) {
    background: rgba(0, 212, 255, 0.18);
    border-color: var(--primary-color);
}

.preview-nav-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.preview-nav-prev {
    left: 0.75rem;
}

.preview-nav-next {
    right: 0.75rem;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    margin-top: 0.9rem;
}

.preview-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
}

.preview-actions .btn {
    flex: 1 1 0;
    width: calc(50% - 0.375rem);
    max-width: calc(50% - 0.375rem);
    justify-content: center;
}

#removeBtn {
    background: linear-gradient(135deg, #ff5b5b, #d93636);
    color: #fff;
    border: none;
}

#removeBtn:hover:not(:disabled) {
    box-shadow: 0 0 20px rgba(255, 91, 91, 0.28);
}

.auto-extract-info {
    font-size: 0.85rem;
    color: var(--success-color);
    margin-top: 0.25rem;
    text-align: center;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ===== Loading Section ===== */
.loading-section {
    text-align: center;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 212, 255, 0.2);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-section p {
    color: var(--text-secondary);
}

.processing-info {
    font-size: 0.85rem;
    color: var(--primary-color);
}

/* ===== Results Section ===== */
.results-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.results-header h3 {
    color: var(--primary-color);
    font-size: 1.3rem;
}

.results-actions {
    display: flex;
    gap: 0.5rem;
}

.results-content {
    margin-bottom: 1.5rem;
}

.results-list {
    display: grid;
    gap: 1.5rem;
}

.result-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.18);
    padding: 1rem;
}

.result-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.result-card-index,
.result-card-confidence {
    color: var(--primary-color);
    font-weight: 600;
}

.result-card-name {
    color: var(--text-secondary);
    word-break: break-word;
}

.result-card-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 1.5rem;
    align-items: flex-start;
}

.results-image-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    min-height: 220px;
}

.result-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    display: block;
}

.results-text-container {
    display: flex;
    flex-direction: column;
}

.result-text-output {
    width: 100%;
    min-height: auto;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

.results-stats {
    display: flex;
    gap: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.results-stats span {
    font-size: 0.95rem;
}

.results-stats strong {
    color: var(--primary-color);
    margin-left: 0.5rem;
}

/* ===== Buttons ===== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.5);
}

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

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

.btn-success {
    background: linear-gradient(135deg, var(--success-color), #00a876);
    color: var(--dark-bg);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(0, 200, 150, 0.3);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

#copyBtn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--dark-bg);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.2);
}

#copyBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0 28px rgba(0, 212, 255, 0.35);
}

#downloadBtn {
    background: linear-gradient(135deg, var(--success-color), #00a876);
    color: var(--dark-bg);
    box-shadow: 0 0 20px rgba(0, 200, 150, 0.18);
}

#downloadBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0 28px rgba(0, 200, 150, 0.3);
}

#resetBtn {
    background: linear-gradient(135deg, var(--danger-color), #d91f4d);
    color: #fff;
    box-shadow: 0 0 20px rgba(255, 51, 51, 0.18);
}

#resetBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0 28px rgba(255, 51, 51, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== Footer ===== */
.footer {
    background: linear-gradient(135deg, #0f1530 0%, #1a1f3a 100%);
    border-top: 2px solid var(--primary-color);
    padding: 2rem;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;
}

.footer-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer-links {
    display: flex;
    gap: 2rem;
}

.footer-links a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

.footer-links a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    :root {
        --navbar-height: 82px;
    }

    .container {
        padding: 1rem;
    }

    .navbar-container {
        padding: 0 1rem;
    }

    .navbar-info {
        gap: 0.6rem;
    }

    .tools-select {
        min-width: 160px;
    }

    .header-section h1 {
        font-size: 1.8rem;
    }

    .rules-list {
        grid-template-columns: 1fr;
    }

    .upload-section,
    .preview-section,
    .results-section,
    .rules-section,
    .header-section {
        padding: 1.25rem;
    }

    .preview-container {
        display: flex;
        width: 100%;
    }

    .preview-image-frame {
        height: 260px;
        overflow: hidden;
    }

    .preview-image {
        min-width: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        object-fit: cover;
    }

    .preview-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .preview-counter {
        left: 50%;
        bottom: 0.5rem;
        transform: translateX(-50%);
        text-align: center;
    }

    .preview-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .preview-actions .btn {
        flex-basis: 100%;
        width: 100%;
        max-width: 100%;
        min-height: 52px;
        font-size: 0.95rem;
    }

    .preview-nav-btn {
        width: 38px;
        height: 38px;
    }

    .preview-nav-prev {
        left: 0.5rem;
    }

    .preview-nav-next {
        right: 0.5rem;
    }

    .result-card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .results-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .results-actions {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }

    .results-actions .btn {
        justify-content: center;
    }

    .results-image-container {
        min-height: 160px;
        padding: 0.75rem;
    }

    .result-image {
        max-height: 220px;
    }

    .auto-extract-info {
        text-align: center;
    }

    .footer-content {
        flex-direction: column;
        gap: 1rem;
    }

    .footer-links {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    :root {
        --navbar-height: 78px;
    }

    .container {
        padding: 0.75rem;
    }

    .header-section h1 {
        font-size: 1.3rem;
    }

    .header-section {
        padding: 1rem;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    .logo-icon {
        font-size: 1.5rem;
    }

    .navbar-info {
        flex-direction: column;
        align-items: stretch;
        gap: 0.55rem;
    }

    .tools-select {
        min-width: 0;
        width: 100%;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .upload-section,
    .preview-section,
    .results-section,
    .rules-section {
        padding: 1rem;
        border-radius: 10px;
    }

    .upload-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .results-stats {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        flex-wrap: nowrap;
    }

    .results-stats span {
        font-size: 0.82rem;
        white-space: nowrap;
    }

    .drag-drop-zone {
        padding: 1rem 0.25rem;
    }

    .drag-drop-zone h3 {
        font-size: 1.15rem;
    }

    .drag-drop-zone p,
    .processing-info,
    .auto-extract-info {
        font-size: 0.8rem;
    }

    .preview-image-frame {
        height: 240px;
    }

    .preview-image {
        min-height: 0;
    }

    .preview-actions .btn {
        min-height: 54px;
        padding: 0.85rem 1rem;
        font-size: 0.95rem;
    }

    .preview-nav-btn {
        width: 34px;
        height: 34px;
    }

    .preview-nav-btn i {
        font-size: 0.85rem;
    }

    .preview-counter {
        min-width: 70px;
        padding: 0.28rem 0.65rem;
        font-size: 0.85rem;
    }

    .results-image-container {
        min-height: 120px;
        padding: 0.6rem;
    }

    .result-image {
        max-height: 160px;
    }

    .result-card {
        padding: 0.85rem;
    }

    .result-card-header {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 0.4rem 0.75rem;
        margin-bottom: 0.75rem;
    }

    .result-card-index {
        grid-column: 1;
        grid-row: 1;
    }

    .result-card-confidence {
        grid-column: 2;
        grid-row: 1;
        text-align: right;
        white-space: nowrap;
    }

    .result-card-name {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
    }

    .result-text-output {
        padding: 0.85rem;
        font-size: 0.88rem;
        line-height: 1.45;
    }

    .results-actions {
        grid-template-columns: 1fr;
    }

    .results-actions .btn {
        width: 100%;
    }

    .results-stats span {
        font-size: 0.9rem;
    }

    .results-stats {
        gap: 1rem;
        flex-wrap: wrap;
    }
}
