/* ============================================
   Design Tokens
   ============================================ */
:root {
    --bg-primary: #0a0a14;
    --bg-secondary: #10101e;
    --bg-card: rgba(18, 18, 35, 0.85);
    --bg-card-hover: rgba(25, 25, 45, 0.9);
    --border-color: rgba(99, 102, 241, 0.15);
    --border-hover: rgba(99, 102, 241, 0.35);

    --text-primary: #e8eaf0;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --accent-indigo: #6366f1;
    --accent-cyan: #22d3ee;
    --accent-green: #22c55e;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;

    --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
    --gradient-success: linear-gradient(135deg, #22c55e, #10b981);
    --gradient-glow: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 60%);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 0 0 1px var(--border-color);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.1);

    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    background-image:
        radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(34, 211, 238, 0.04) 0%, transparent 50%);
}

/* ============================================
   App Container
   ============================================ */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 40px;
}

/* ============================================
   Header
   ============================================ */
.app-header {
    text-align: center;
    padding: 48px 20px 40px;
    position: relative;
}

.header-glow {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 200px;
    background: var(--gradient-glow);
    pointer-events: none;
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #e8eaf0 0%, #a5b4fc 50%, #22d3ee 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.app-header .icon {
    -webkit-text-fill-color: initial;
    font-size: 1.8rem;
}

.app-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 300;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
    transition: border-color var(--transition-normal);
    animation: fadeSlideUp 0.5s ease forwards;
    opacity: 0;
}

.card:hover {
    border-color: var(--border-hover);
}

.card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Info Banner */
.info-banner {
    padding: 16px 24px;
    border-left: 3px solid var(--accent-cyan);
    background: rgba(34, 211, 238, 0.04);
}

.info-banner .info-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.info-banner a {
    color: var(--accent-cyan);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.info-banner a:hover {
    color: #67e8f9;
    text-decoration: underline;
}

/* ============================================
   Upload / Drop Zone
   ============================================ */
.drop-zone {
    border: 2px dashed rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-md);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    background: rgba(99, 102, 241, 0.03);
    position: relative;
    overflow: hidden;
}

.drop-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.08), transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent-indigo);
    background: rgba(99, 102, 241, 0.06);
}

.drop-zone:hover::before,
.drop-zone.drag-over::before {
    opacity: 1;
}

.drop-zone-content {
    position: relative;
    z-index: 1;
}

.drop-icon {
    color: var(--accent-indigo);
    margin-bottom: 16px;
    transition: transform var(--transition-normal);
}

.drop-zone:hover .drop-icon {
    transform: translateY(-4px);
}

.drop-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.drop-subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.file-select-btn {
    display: inline-block;
    padding: 10px 28px;
    background: var(--gradient-primary);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.file-select-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

/* File Info */
.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-sm);
}

.file-icon {
    font-size: 1.4rem;
}

.file-name {
    font-weight: 500;
    font-size: 0.9rem;
    flex: 1;
}

.file-size {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.file-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.file-remove:hover {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
}

/* ============================================
   Settings
   ============================================ */
.settings-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 20px;
    align-items: end;
}

.setting-item label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-item select {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.setting-item select:focus {
    outline: none;
    border-color: var(--accent-indigo);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   Action Buttons
   ============================================ */
.action-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0);
    transition: background var(--transition-fast);
}

.btn:hover::after {
    background: rgba(255, 255, 255, 0.08);
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn:disabled::after {
    display: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--gradient-success);
    color: white;
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
}

.btn-success:hover:not(:disabled) {
    box-shadow: 0 6px 24px rgba(34, 197, 94, 0.4);
    transform: translateY(-1px);
}

.btn-icon {
    font-size: 1.1rem;
}

/* ============================================
   Progress Bar
   ============================================ */
.progress-container {
    margin-top: 24px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.progress-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-indigo);
}

.progress-bar {
    height: 6px;
    background: rgba(99, 102, 241, 0.12);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-primary);
    border-radius: 3px;
    transition: width 0.4s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3));
    animation: progressShimmer 1.5s infinite;
}

@keyframes progressShimmer {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

.progress-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ============================================
   Results Summary
   ============================================ */
.results-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.result-stat {
    text-align: center;
    padding: 20px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.result-stat-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.result-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-stat.success .result-stat-value {
    color: var(--accent-green);
}

.result-stat.warning .result-stat-value {
    color: var(--accent-amber);
}

.result-stat.error .result-stat-value {
    color: var(--accent-red);
}

/* ============================================
   Data Table
   ============================================ */
.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.table-header h2 {
    margin-bottom: 0;
}

.table-badge {
    font-size: 0.75rem;
    padding: 4px 12px;
    background: rgba(99, 102, 241, 0.12);
    color: var(--accent-indigo);
    border-radius: 20px;
    font-weight: 500;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 3px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

thead th {
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.72rem;
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}

thead th.sortable:hover {
    background: rgba(99, 102, 241, 0.16);
    color: var(--text-primary);
}

.sort-indicator {
    font-size: 0.65rem;
    margin-left: 4px;
    color: var(--accent-cyan);
}

tbody tr {
    transition: background var(--transition-fast);
}

tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Closing price column */
td.price-cell {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

td.price-cell.has-price {
    color: var(--accent-green);
}

td.price-cell.no-price {
    color: var(--text-muted);
    font-weight: 400;
    font-style: italic;
}

td.price-cell.loading {
    color: var(--accent-indigo);
}

/* Price change rate columns */
td.price-cell.change-up {
    color: #22c55e;
}

td.price-cell.change-down {
    color: #ef4444;
}

/* ============================================
   Error Log
   ============================================ */
.error-log {
    max-height: 240px;
    overflow-y: auto;
    font-size: 0.8rem;
    font-family: 'SF Mono', 'Consolas', monospace;
}

.error-log::-webkit-scrollbar {
    width: 4px;
}

.error-log::-webkit-scrollbar-thumb {
    background: rgba(239, 68, 68, 0.3);
    border-radius: 2px;
}

.error-entry {
    padding: 8px 12px;
    border-left: 3px solid var(--accent-red);
    background: rgba(239, 68, 68, 0.05);
    margin-bottom: 6px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.error-entry .error-code {
    color: var(--accent-amber);
    font-weight: 600;
}

/* ============================================
   Footer
   ============================================ */
.app-footer {
    text-align: center;
    padding: 24px 20px;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ============================================
   Responsive — Tablet
   ============================================ */
@media (max-width: 768px) {
    .app-container {
        padding: 12px 12px 32px;
    }

    .app-header {
        padding: 28px 12px 24px;
    }

    .app-header h1 {
        font-size: 1.35rem;
        gap: 8px;
    }

    .app-header .icon {
        font-size: 1.4rem;
    }

    .app-header .subtitle {
        font-size: 0.85rem;
    }

    .header-glow {
        width: 300px;
        height: 120px;
    }

    .card {
        padding: 20px 16px;
        border-radius: var(--radius-md);
        margin-bottom: 14px;
    }

    .card h2 {
        font-size: 1rem;
        margin-bottom: 16px;
    }

    .info-banner {
        padding: 14px 16px;
    }

    .info-banner .info-text {
        font-size: 0.82rem;
        line-height: 1.6;
    }

    .settings-grid {
        grid-template-columns: 1fr 1fr;
        gap: 14px;
    }

    .settings-grid .setting-item:first-child {
        grid-column: 1 / -1;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .results-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .result-stat {
        padding: 14px 8px;
    }

    .result-stat-value {
        font-size: 1.5rem;
    }

    .drop-zone {
        padding: 32px 16px;
    }

    .drop-icon svg {
        width: 48px;
        height: 48px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        justify-content: center;
        padding: 14px 24px;
        font-size: 0.95rem;
    }

    /* テーブル：横スクロールのヒント */
    .table-wrapper {
        position: relative;
    }

    .table-wrapper::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        width: 40px;
        height: 100%;
        background: linear-gradient(to right, transparent, rgba(10, 10, 20, 0.8));
        pointer-events: none;
        z-index: 2;
    }

    table {
        font-size: 0.75rem;
    }

    thead th {
        padding: 10px 10px;
        font-size: 0.65rem;
    }

    tbody td {
        padding: 8px 10px;
    }

    .table-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .error-log {
        max-height: 180px;
        font-size: 0.72rem;
    }

    .app-footer {
        font-size: 0.7rem;
        padding: 16px 12px;
    }
}

/* ============================================
   Responsive — Mobile
   ============================================ */
@media (max-width: 480px) {
    .app-container {
        padding: 8px 8px 24px;
    }

    .app-header {
        padding: 20px 8px 16px;
    }

    .app-header h1 {
        font-size: 1.1rem;
        gap: 6px;
    }

    .app-header .icon {
        font-size: 1.2rem;
    }

    .app-header .subtitle {
        font-size: 0.78rem;
    }

    .header-glow {
        display: none;
    }

    .card {
        padding: 16px 12px;
        border-radius: var(--radius-sm);
        margin-bottom: 10px;
    }

    .card h2 {
        font-size: 0.92rem;
        margin-bottom: 12px;
    }

    .info-banner {
        padding: 12px;
    }

    .info-banner .info-text {
        font-size: 0.78rem;
    }

    .settings-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .setting-item label {
        font-size: 0.7rem;
    }

    .setting-item select {
        font-size: 0.82rem;
        padding: 8px 10px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .drop-zone {
        padding: 24px 12px;
    }

    .drop-icon svg {
        width: 40px;
        height: 40px;
    }

    .drop-text {
        font-size: 0.88rem;
    }

    .drop-subtext {
        font-size: 0.75rem;
    }

    .file-select-btn {
        padding: 10px 24px;
        font-size: 0.85rem;
    }

    .file-info {
        padding: 10px 12px;
        gap: 8px;
    }

    .file-name {
        font-size: 0.82rem;
    }

    .file-size {
        font-size: 0.72rem;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.88rem;
    }

    .results-stats {
        gap: 6px;
    }

    .result-stat {
        padding: 10px 6px;
    }

    .result-stat-value {
        font-size: 1.2rem;
    }

    .result-stat-label {
        font-size: 0.68rem;
    }

    table {
        font-size: 0.7rem;
    }

    thead th {
        padding: 8px 8px;
        font-size: 0.6rem;
    }

    tbody td {
        padding: 7px 8px;
    }

    .progress-label,
    .progress-value {
        font-size: 0.78rem;
    }

    .progress-detail {
        font-size: 0.72rem;
    }
}

/* ============================================
   Animation Delays
   ============================================ */
.card:nth-child(2) {
    animation-delay: 0.05s;
}

.card:nth-child(3) {
    animation-delay: 0.1s;
}

.card:nth-child(4) {
    animation-delay: 0.15s;
}

.card:nth-child(5) {
    animation-delay: 0.2s;
}

.card:nth-child(6) {
    animation-delay: 0.25s;
}

.card:nth-child(7) {
    animation-delay: 0.3s;
}

/* Loading spinner for button */
.btn.loading .btn-icon {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}