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

:root {
    --primary-color: #0f0f10;
    --secondary-color: #1a1a1d;
    --success-color: #10b981;
    --danger-color: #f87171;
    --dark-bg: #050505;
    --slate-900: #050505;
    --slate-800: #0d0d0f;
    --slate-700: #161618;
    --slate-600: #202024;
    --slate-500: #2a2a2e;
    --slate-400: #b5b5b9;
    --slate-300: #d6d6d6;
    --text-primary: #f5f5f5;
    --text-secondary: #c7c7c7;
}

body {
    font-family: 'Space Mono', monospace;
    background: var(--dark-bg);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 80px 12px 160px 12px;
    letter-spacing: 0.015em;
    transition: background-color 0.5s ease;
}

body.portfolio-low {
    background: rgba(15, 5, 5, 0.95);
    background-image: linear-gradient(135deg, rgba(15, 5, 5, 0.98) 0%, rgba(20, 5, 5, 0.95) 50%, rgba(15, 5, 5, 0.98) 100%);
}

body.portfolio-high {
    background: rgba(5, 15, 8, 0.95);
    background-image: linear-gradient(135deg, rgba(5, 15, 8, 0.98) 0%, rgba(5, 20, 10, 0.95) 50%, rgba(5, 15, 8, 0.98) 100%);
}

.container {
    max-width: 1280px;
    margin: 0 auto;
}

/* Header */
.header {
    margin-bottom: 32px;
    position: relative;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-primary);
    position: fixed;
    left: 24px;
    top: 24px;
    z-index: 50;
}

.header .add-btn {
    position: fixed;
    right: 24px;
    top: 24px;
    z-index: 50;
}

.header .user-menu {
    position: fixed;
    right: 150px;
    top: 24px;
    z-index: 50;
    margin-right: 10px;
}

.subtitle {
    color: var(--slate-400);
    font-size: 0.875rem;
}

/* Summary Card */
.summary-card {
    background: transparent;
    border-radius: 0;
    padding: 32px 0;
    margin: 0 auto 32px;
    border: none;
    max-width: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    align-items: start;
    width: 100%;
    max-width: 960px;
    justify-items: center;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-secondary);
    text-align: center;
}

.summary-item.left-align {
    text-align: left;
}

.summary-item.right-align {
    text-align: right;
}

.summary-item.center-align {
    text-align: center;
}

.summary-item.primary-total {
    grid-column: 1 / -1;
    align-items: center;
    text-align: center;
    padding: 12px 0 24px;
    border-bottom: none;
    margin-bottom: 4px;
    background: transparent;
    border: none;
}

.summary-item.primary-total .summary-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.summary-item.primary-total .portfolio-value {
    font-size: clamp(2.5rem, 3.5vw, 3.5rem);
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: none;
    color: var(--text-primary);
    word-break: break-word;
    overflow-wrap: break-word;
}

.summary-item:not(.primary-total) .summary-value,
.summary-item:not(.primary-total) .last-updated {
    color: var(--text-primary);
    font-weight: 500;
}

.summary-label {
    color: var(--slate-400);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.summary-label.emphasis {
    color: var(--text-secondary);
    letter-spacing: 0.2em;
}

.summary-value {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1;
}

.summary-value-with-timestamp {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.timestamp-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    opacity: 0.6;
    cursor: help;
    position: relative;
}

.timestamp-icon:hover {
    opacity: 1;
}

.timestamp-icon::before {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23b5b5b9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpolyline points='12 6 12 12 16 14'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.timestamp-icon[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--slate-800);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    white-space: nowrap;
    margin-bottom: 5px;
    border: 1px solid var(--slate-700);
    z-index: 100;
    pointer-events: none;
}

.portfolio-value {
    font-size: clamp(2.2rem, 2.6vw, 3rem);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: 0.2em;
    text-align: center;
}

.portfolio-change {
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.portfolio-change.positive {
    color: var(--success-color) !important;
}

.portfolio-change.negative {
    color: var(--danger-color) !important;
}

.last-updated {
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--slate-400);
}

/* Holdings Header */
.holdings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
    border-top: 1px solid rgba(63, 63, 70, 0.35);
    padding-top: 20px;
}

.holdings-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-secondary);
}


.add-btn {
    background: #ffffff;
    color: #111111;
    border: 1px solid rgba(209, 213, 219, 0.9);
    padding: 10px 20px;
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    box-shadow: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.add-btn-text {
    display: inline;
}

.add-btn-icon {
    display: none;
    width: 18px;
    height: 18px;
}

.add-btn:hover {
    background: #f3f4f6;
    border-color: rgba(156, 163, 175, 0.8);
}

/* Portfolio Grid */
.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 16px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px 20px;
    color: var(--slate-400);
}

.empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 0.9rem;
}

/* Coin Card */
.coin-card {
    background: #111216;
    border-radius: 16px;
    padding: 26px;
    border: none;
    transition: transform 0.2s ease;
    animation: slideIn 0.3s ease-out;
    cursor: move;
    user-select: none;
}

.coin-card:hover {
    transform: translateY(-2px);
}

.coin-card.dragging {
    opacity: 0.92;
    cursor: grabbing;
    transform: rotate(1deg) scale(0.99);
}

.coin-card-placeholder {
    background: rgba(38, 38, 38, 0.25);
    border: 2px dashed rgba(82, 82, 91, 0.6);
    border-radius: 12px;
    opacity: 0.5;
}

.coin-card.drag-over {
    transform: scale(1.02);
}

.coin-card.drag-before {
    transform: scale(1.02);
}

.coin-card.pulse-green {
    animation: pulse-green 1s ease-in-out;
}

.coin-card.pulse-red {
    animation: pulse-red 1s ease-in-out;
}

.coin-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.coin-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.coin-info > div {
    display: flex;
    flex-direction: column;
}

.coin-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.coin-name {
    font-weight: 400;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.coin-symbol {
    color: var(--slate-400);
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-top: 0;
}

.edit-btn {
    color: var(--slate-400);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.edit-btn:hover {
    color: var(--slate-200);
}

.coin-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.coin-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 6px;
}

.coin-detail-row:last-child {
    padding-top: 10px;
    margin-top: 10px;
    border-top: 1px solid var(--slate-700);
    padding-bottom: 0;
    align-items: baseline;
}

.detail-label {
    color: var(--slate-400);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.coin-detail-row:last-child .detail-label {
    font-size: 0.8rem;
}

.detail-value {
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.detail-value.large {
    font-size: 1.0625rem;
    font-weight: 400;
}

.detail-value.change-small {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
}

/* Footer */
.footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20px 28px;
    border: none;
    border-top: 1px solid rgba(70, 70, 78, 0.4);
    border-radius: 0;
    background: var(--dark-bg);
    z-index: 40;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.footer-content {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 24px;
}

.footer-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.footer-right {
    display: flex;
    align-items: center;
}

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

.refresh-timer {
    color: var(--slate-400);
    font-size: 0.65rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.refresh-status-text {
    color: var(--text-secondary);
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.api-stats {
    display: flex;
    gap: 24px;
    align-items: center;
}

.api-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
}

.api-label {
    color: var(--slate-400);
    opacity: 0.6;
    font-size: 0.65rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.api-count {
    color: var(--text-primary);
    font-weight: 500;
    opacity: 0.8;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.api-count.safe,
.api-count.warning,
.api-count.danger {
    /* Override any color classes - keep grey */
    color: var(--slate-500) !important;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 16px;
}

.modal.hidden {
    display: none;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

.modal-content {
    background: var(--slate-800);
    border-radius: 16px;
    padding: 32px;
    max-width: 28rem;
    width: 100%;
    border: 1px solid var(--slate-700);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
    position: relative;
}

.modal-content-small {
    max-width: 24rem;
    padding: 24px;
}

.modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--slate-400);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.modal-close-btn:hover {
    background: var(--slate-700);
    color: var(--slate-200);
}

.confirm-message {
    color: var(--slate-300);
    margin: 16px 0 24px;
    line-height: 1.6;
    font-size: 0.875rem;
}

.modal-title {
    font-size: 1rem;
    font-weight: 400;
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 24px;
}

.form-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    margin-bottom: 8px;
    color: var(--slate-300);
}

.form-select,
.form-input {
    width: 100%;
    background: var(--slate-700);
    border: 1px solid var(--slate-600);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 0.75rem;
    transition: all 0.2s;
}

.form-select:focus,
.form-input:focus {
    outline: none;
    border-color: rgba(245, 245, 245, 0.3);
    box-shadow: 0 0 0 1px rgba(245, 245, 245, 0.12);
}

.search-container {
    position: relative;
}

.suggestions-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--slate-800);
    border: 1px solid var(--slate-700);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    margin-top: -1px;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
    border-bottom: 1px solid var(--slate-700);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: var(--slate-700);
}

.suggestion-item img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.suggestion-item .coin-info {
    display: flex;
    flex-direction: column;
}

.suggestion-item .coin-name {
    font-size: 0.75rem;
    font-weight: 400;
}

.suggestion-item .coin-symbol {
    font-size: 0.65rem;
    color: var(--slate-400);
}

.modal-buttons {
    display: flex;
    gap: 12px;
}

.btn-secondary,
.btn-primary {
    flex: 1;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    font-size: 0.75rem;
}

.btn-secondary {
    background: #1c1c1f;
    color: var(--text-primary);
    border: 1px solid rgba(70, 70, 78, 0.5);
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.btn-secondary:hover {
    background: #252528;
}

.btn-primary {
    background: #ffffff;
    color: #111111;
    border: 1px solid rgba(209, 213, 219, 0.9);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.btn-primary:hover {
    background: #f3f4f6;
    border-color: rgba(156, 163, 175, 0.8);
}

.btn-danger {
    background: #1c1c1f;
    color: var(--danger-color);
    flex: 1;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    font-size: 0.75rem;
    border: 1px solid rgba(70, 70, 78, 0.4);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.btn-danger:hover {
    background: #2a2a2e;
    color: var(--text-primary);
}

.form-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse-green {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(245, 245, 245, 0.08);
    }
}

@keyframes pulse-red {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(66, 66, 66, 0.25);
    }
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 70px 12px 240px 12px;
    }

    .summary-grid {
        grid-template-columns: 1fr;
        gap: 18px;
        justify-items: center;
    }

    .summary-item.primary-total {
        padding: 12px 0 20px;
    }

    .header {
        margin-bottom: 24px;
    }

    .header h1 {
        font-size: 1.2rem;
        left: 12px;
        top: 12px;
    }

    .header .add-btn {
        right: 12px;
        top: 12px;
        width: 38px;
        height: 38px;
        padding: 10px;
        justify-content: center;
    }

    .add-btn-text {
        display: none;
    }

    .add-btn-icon {
        display: block;
        width: 18px;
        height: 18px;
    }

    .header .user-menu {
        right: 55px;
        top: 12px;
    }

    .user-menu-text {
        display: none !important;
    }

    .user-menu-icon {
        display: block !important;
        width: 18px;
        height: 18px;
    }

    .user-menu-btn {
        width: 38px;
        height: 38px;
        padding: 10px;
        justify-content: center;
        align-items: center;
    }

    .summary-card {
        padding: 24px 0;
    }

    .portfolio-value {
        font-size: clamp(2.4rem, 9vw, 3rem);
    }

    .holdings-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .portfolio-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .footer {
        left: 0;
        right: 0;
        bottom: 0;
        padding: 18px 20px;
        border-radius: 0;
    }

    .footer-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .footer-left,
    .footer-right {
        width: 100%;
    }

    .api-stats {
        flex-direction: row;
        gap: 16px;
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .refresh-info {
        width: 100%;
    }
}

@media (max-width: 480px) {
    body {
        padding: 65px 10px 260px 10px;
    }

    .header h1 {
        font-size: 1.1rem;
        left: 10px;
        top: 10px;
    }

    .header .add-btn {
        right: 10px;
        top: 10px;
        width: 38px;
        height: 38px;
        padding: 10px;
    }

    .add-btn-icon {
        width: 18px;
        height: 18px;
    }

    .header .user-menu {
        right: 55px;
        top: 10px;
    }

    .user-menu-text {
        display: none !important;
    }

    .user-menu-icon {
        display: block !important;
        width: 18px;
        height: 18px;
    }

    .user-menu-btn {
        width: 38px;
        height: 38px;
        padding: 10px;
        justify-content: center;
        align-items: center;
    }

    .add-btn-text {
        display: none !important;
    }

    .add-btn-icon {
        display: block !important;
        width: 18px;
        height: 18px;
    }

    .add-btn {
        width: 38px;
        height: 38px;
        padding: 10px;
        justify-content: center;
        align-items: center;
    }

    .portfolio-value {
        font-size: clamp(2.1rem, 10vw, 2.8rem);
    }

    .coin-card {
        padding: 20px;
    }

    .footer {
        left: 0;
        right: 0;
        bottom: 0;
        padding: 16px;
        border-radius: 0;
    }
}

/* User Menu Styles */
.user-menu {
    position: relative;
    display: inline-block;
}

.user-menu-btn {
    background: #1c1c1f;
    color: var(--text-primary);
    border: 1px solid rgba(70, 70, 78, 0.5);
    padding: 10px 20px;
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-menu-text {
    display: inline;
}

.user-menu-icon {
    display: none;
    width: 18px;
    height: 18px;
}

.user-menu-btn:hover {
    background: #252528;
    border-color: rgba(70, 70, 78, 0.8);
}


.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--slate-800);
    border: 1px solid var(--slate-700);
    border-radius: 8px;
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.user-menu:hover .user-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-item {
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
    border-bottom: 1px solid var(--slate-700);
    letter-spacing: 0.1em;
}

.user-dropdown-item:last-child {
    border-bottom: none;
}

.user-dropdown-item:hover {
    background: var(--slate-700);
}

.auth-error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.75rem;
}

.auth-status {
    margin-top: 16px;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    text-align: center;
}

.auth-status.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--success-color);
    color: var(--success-color);
}

.auth-status.loading {
    color: var(--slate-400);
}