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

:root {
    --bg: #ffffff;
    --text: #1a1a1a;
    --header-bg: #111111;
    --header-subtle: #888888;
    --card-bg: #ffffff;
    --border: #e8e8e8;
    --input-bg: #ffffff;
    --input-border: #d4d4d4;
    --input-placeholder: #a0a0a0;
    --muted: #666666;
    --table-head-bg: #f5f5f5;
    --table-row-border: #eeeeee;
    --row-hover: #fafafa;
    --toggle-bg: #111111;
    --toggle-text: #ffffff;
    --toggle-hover: #333333;
    --btn-secondary-bg: #111111;
    --btn-secondary-text: #ffffff;
    --btn-secondary-hover: #2f2f2f;
    --soft-bg: #f7f7f8;
}

body[data-theme="dark"] {
    --bg: #101218;
    --text: #edf0f5;
    --header-bg: #0a0c11;
    --header-subtle: #98a2b3;
    --card-bg: #171a22;
    --border: #2c3140;
    --input-bg: #1c2230;
    --input-border: #394155;
    --input-placeholder: #8b95a7;
    --muted: #a9b2c1;
    --table-head-bg: #171d28;
    --table-row-border: #2b3242;
    --row-hover: #1a2030;
    --toggle-bg: #f3f4f6;
    --toggle-text: #111827;
    --toggle-hover: #e5e7eb;
    --btn-secondary-bg: #e5e7eb;
    --btn-secondary-text: #111827;
    --btn-secondary-hover: #d1d5db;
    --soft-bg: #1f2533;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ===== Header ===== */
.header {
    background-color: var(--header-bg);
    padding: 18px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 1.35rem;
    font-weight: 900;
    color: #ffffff;
    letter-spacing: 1.5px;
}

.header-subtitle {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--header-subtle);
    letter-spacing: 2.5px;
    text-transform: uppercase;
}

/* ===== Main Container ===== */
.page-layout {
    max-width: 1220px;
    margin: 0 auto;
    padding: 32px 24px 64px;
    display: flex;
    align-items: flex-start;
    gap: 28px;
}

.container {
    flex: 1;
    min-width: 0;
    max-width: 800px;
}

/* ===== Controls Bar ===== */
.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.search-input {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s ease;
}

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

.search-input:focus {
    border-color: #555555;
}

.sort-select {
    height: 44px;
    padding: 0 36px 0 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    appearance: none;
    /* -webkit-appearance: none; */
    /* background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); */
    background-repeat: no-repeat;
    /* background-position: right 12px center; */
    transition: border-color 0.2s ease;
}

.sort-select:focus {
    border-color: #555555;
}

.stock-count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 1.5px;
    white-space: nowrap;
}

.theme-toggle {
    height: 44px;
    padding: 0 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--toggle-text);
    background: var(--toggle-bg);
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.theme-toggle:hover {
    background: var(--toggle-hover);
}

.theme-toggle:active {
    transform: scale(0.98);
}

/* ===== Stock Table ===== */
.stock-table {
    width: 100%;
    border-collapse: collapse;
}

.stock-table thead th {
    padding: 10px 16px;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: left;
    background-color: var(--table-head-bg);
    border-bottom: 1px solid var(--border);
}

.stock-table thead th:nth-child(2) {
    text-align: right;
}

.stock-table thead th:nth-child(3) {
    text-align: right;
}

.stock-table thead th:nth-child(4) {
    text-align: center;
}

.stock-table tbody tr {
    border-bottom: 1px solid var(--table-row-border);
    transition: background-color 0.15s ease;
}

.stock-table tbody tr:hover {
    background-color: var(--row-hover);
}

.stock-table tbody td {
    padding: 16px 16px;
    vertical-align: middle;
}

.stock-table tbody td:nth-child(2),
.stock-table tbody td:nth-child(3) {
    text-align: right;
}

.stock-table tbody td:nth-child(4) {
    text-align: center;
}

/* Stock name cell */
.stock-ticker {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
}

.stock-name {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--muted);
    margin-top: 2px;
}

/* Price */
.stock-price {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
}

/* Change badge */
.stock-change {
    font-size: 0.82rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.stock-change.positive {
    color: #16a34a;
}

.stock-change.negative {
    color: #dc2626;
}

.stock-change .arrow {
    font-size: 0.6rem;
}

.wishlist-btn {
    height: 30px;
    padding: 0 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--btn-secondary-text);
    background: var(--btn-secondary-bg);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

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

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

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

/* ===== Sidebar ===== */
.sidebar {
    width: 350px;
    flex-shrink: 0;
    position: sticky;
    top: 80px;
}

.sidebar-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
}

.wishlist-card {
    margin-top: 14px;
}

.wishlist-empty {
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--soft-bg);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}

.wishlist-list {
    list-style: none;
    display: none;
    flex-direction: column;
    gap: 8px;
}

.wishlist-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--soft-bg);
}

.wishlist-stock {
    min-width: 0;
}

.wishlist-symbol {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text);
}

.wishlist-name {
    font-size: 0.72rem;
    color: var(--muted);
}

.wishlist-remove {
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    border-radius: 6px;
    height: 28px;
    padding: 0 8px;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
}

.sidebar-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 6px;
}

.sidebar-desc {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 22px;
    line-height: 1.5;
}

/* Steps */
.steps-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 24px;
}

.step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.step-number {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--header-bg);
    color: var(--toggle-text);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.step-content {
    flex: 1;
    min-width: 0;
}

.step-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 3px;
}

.step-text {
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.55;
}

.step-text a {
    color: var(--text);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s ease;
}

.step-text a:hover {
    color: #444444;
}

/* API Key Section */
.api-key-section {
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.api-key-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    display: block;
    margin-bottom: 8px;
}

.api-key-row {
    display: flex;
    gap: 8px;
}

.api-key-input {
    flex: 1;
    height: 40px;
    padding: 0 12px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    color: var(--text);
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.api-key-input::placeholder {
    color: var(--input-placeholder);
}

.api-key-input:focus {
    border-color: #555555;
    background: var(--bg);
}

.api-key-btn {
    height: 40px;
    padding: 0 18px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
    background: #111111;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.api-key-btn:hover {
    background: #333333;
}

.api-key-btn:active {
    transform: scale(0.97);
}

.api-key-btn:disabled {
    background: #6f6f6f;
    cursor: not-allowed;
    transform: none;
}

.api-key-hint {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 8px;
}

.api-key-status {
    min-height: 1.2em;
    margin-top: 8px;
    font-size: 0.72rem;
    font-weight: 600;
}

.api-key-status.info {
    color: #2563eb;
}

.api-key-status.success {
    color: #16a34a;
}

.api-key-status.warn {
    color: #b45309;
}

.api-key-status.error {
    color: #dc2626;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .page-layout {
        flex-direction: column;
        padding: 20px 16px 48px;
    }

    .sidebar {
        width: 100%;
        position: static;
        order: -1;
    }

    .container {
        width: 100%;
        max-width: none;
    }
}

@media (max-width: 600px) {
    .header-inner {
        padding: 0 16px;
    }

    .controls {
        flex-wrap: wrap;
    }

    .search-input {
        width: 100%;
        flex: none;
    }

    .sort-select {
        flex: 1;
    }

    .stock-table thead th,
    .stock-table tbody td {
        padding: 12px 10px;
    }

    .stock-ticker {
        font-size: 0.85rem;
    }

    .stock-name {
        font-size: 0.72rem;
    }

    .stock-price {
        font-size: 0.85rem;
    }

    .sidebar-card {
        padding: 18px;
    }
}
