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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.6;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

h1 {
    font-size: 1.75rem;
    color: #1a1a2e;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: #666;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

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

.card-body {
    padding: 0.75rem;
}

.form-panel .card {
    margin-bottom: 0.75rem;
}

.panel {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.panel h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e8e8e8;
}

.panel h3 {
    font-size: 0.95rem;
    margin: 1rem 0 0.5rem;
    color: #555;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.25rem;
}

.form-group input {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.form-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    background: #fff;
    cursor: pointer;
}

.form-group select:focus {
    outline: none;
    border-color: #4a6cf7;
    box-shadow: 0 0 0 2px rgba(74,108,247,0.15);
}

hr {
    border: none;
    border-top: 1px solid #e8e8e8;
    margin: 0.75rem 0;
}

.form-group input:read-only {
    background: #f5f5f5;
    color: #666;
    cursor: default;
}

.form-group input:focus {
    outline: none;
    border-color: #4a6cf7;
    box-shadow: 0 0 0 2px rgba(74,108,247,0.15);
}

.coupon-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}

.coupon-row input {
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85rem;
}

.coupon-row input:read-only {
    background: #f5f5f5;
    color: #666;
    cursor: default;
}

.btn-remove, .btn-add {
    padding: 0.4rem 0.75rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-remove {
    background: #fee2e2;
    color: #dc2626;
}

.btn-add {
    background: #e0e7ff;
    color: #4a6cf7;
    margin-top: 0.25rem;
}

.btn-calc {
    width: 100%;
    padding: 0.75rem;
    margin-top: 1rem;
    background: #4a6cf7;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-calc:hover {
    background: #3b5de7;
}

.btn-calc:disabled {
    background: #a5b4fc;
    cursor: not-allowed;
}

.error {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 4px;
    color: #dc2626;
    font-size: 0.85rem;
}

.hidden {
    display: none;
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.result-item {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    background: #f8f9ff;
    border-radius: 6px;
}

.result-item.highlight {
    background: #e0e7ff;
    border: 1px solid #c7d2fe;
}

.result-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tip-icon {
    position: relative;
    cursor: help;
    font-size: 0.8rem;
    color: #a5b4fc;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
}

.tip-icon::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2e;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    white-space: normal;
    width: 220px;
    text-align: center;
    line-height: 1.4;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 10;
}

.tip-icon::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #1a1a2e;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
}

.tip-icon:hover::after,
.tip-icon:hover::before {
    opacity: 1;
}

.result-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-top: 0.25rem;
}

.placeholder {
    text-align: center;
    color: #999;
    padding: 3rem 1rem;
    font-style: italic;
    background: transparent;
    opacity: 1;
    display: block;
    min-height: 0;
    vertical-align: baseline;
    cursor: default;
}

.chart-container {
    position: relative;
    height: 280px;
    margin: 1rem 0 0.5rem;
}

.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    background: #fff;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group input {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #1a1a2e;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-group input:focus {
    outline: none;
    border-color: #4a6cf7;
    box-shadow: 0 0 0 3px rgba(74,108,247,0.12);
}

.btn-filter {
    padding: 0.5rem 1.25rem;
    background: #4a6cf7;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    height: 38px;
}

.btn-filter:hover {
    background: #3b5de7;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    border-top: 3px solid #4a6cf7;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1.2;
}

.stat-card-label {
    font-size: 0.75rem;
    color: #888;
    margin-top: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-table {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.panel-table h2 {
    font-size: 0.9rem;
    font-weight: 700;
    color: #1a1a2e;
    padding: 1rem 1.25rem 0;
    margin: 0;
}

.table-wrapper {
    overflow-x: auto;
    padding: 0 0.25rem;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.stats-table th,
.stats-table td {
    padding: 0.65rem 1rem;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
}

.stats-table th {
    font-size: 0.7rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #fafbfc;
}

.stats-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.stats-table tbody tr:hover {
    background: #eef1ff;
}

.stats-table .mono {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.8rem;
    color: #555;
}

.stats-table .agent {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #666;
    font-size: 0.8rem;
}

.stats-table .num {
    font-weight: 600;
    color: #1a1a2e;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.badge-new {
    background: #eef1ff;
    color: #4a6cf7;
}

.badge-return {
    background: #e8f5e9;
    color: #2e7d32;
}

.rate-status {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    margin-top: 0.2rem;
    min-height: 1em;
}
.rate-status-loading {
    color: #888;
}
.rate-status-ok {
    color: #2e7d32;
}
.rate-status-warn {
    color: #e65100;
}

.section-buy {
    background: #f0fdf4;
}

.section-sell {
    background: #fef2f2;
}

@media (max-width: 768px) {
    .filter-bar {
        flex-wrap: wrap;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .layout {
        grid-template-columns: 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .result-grid {
        grid-template-columns: 1fr;
    }
    .chart-container {
        height: 220px;
    }
}