/* ============================================
   InvestLimit — Design System & Styles
   ============================================ */

:root {
    /* Colors */
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-input: #1e1e2a;
    --bg-modal: #1a1a26;

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-focus: #6366f1;

    --text-primary: #f0f0f5;
    --text-secondary: #9999aa;
    --text-muted: #666677;
    --text-accent: #a5b4fc;

    /* Semantic */
    --color-keep: #22c55e;
    --color-keep-bg: rgba(34, 197, 94, 0.1);
    --color-opportunity: #3b82f6;
    --color-opportunity-bg: rgba(59, 130, 246, 0.1);
    --color-monitor: #f59e0b;
    --color-monitor-bg: rgba(245, 158, 11, 0.1);
    --color-wait: #a78bfa;
    --color-wait-bg: rgba(167, 139, 250, 0.1);
    --color-review: #f97316;
    --color-review-bg: rgba(249, 115, 22, 0.1);
    --color-withdraw: #ef4444;
    --color-withdraw-bg: rgba(239, 68, 68, 0.1);

    /* Accent */
    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', monospace;

    /* Spacing */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    /* Shadows */
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* App container */
.app {
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(139, 92, 246, 0.05) 0%, transparent 50%),
        var(--bg-primary);
}

/* ============ HEADER ============ */
.header {
    border-bottom: 1px solid var(--border-subtle);
    backdrop-filter: blur(20px);
    background: rgba(10, 10, 15, 0.8);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.header-actions {
    display: flex;
    gap: 8px;
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.btn-danger {
    color: var(--color-withdraw);
}

.btn-danger:hover {
    background: var(--color-withdraw-bg);
}

/* ============ MAIN ============ */
.main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ============ CARDS ============ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    transition: border-color 0.3s ease;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

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

.card-header h2 svg {
    color: var(--text-accent);
    opacity: 0.7;
}

/* ============ BADGES ============ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.badge-info {
    background: rgba(99, 102, 241, 0.12);
    color: var(--text-accent);
}

/* ============ INDICATORS ============ */
.indicators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    padding: 20px;
}

.indicator-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.indicator-field label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.indicator-field .unit {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.indicator-field input {
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s ease;
    width: 100%;
}

.indicator-field input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.indicator-field input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.field-hint {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ============ PORTFOLIO TABLE ============ */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.portfolio-table thead th {
    background: rgba(255, 255, 255, 0.02);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
}

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

.portfolio-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.portfolio-table td {
    padding: 10px 12px;
    vertical-align: middle;
}

.portfolio-table .cell-mono {
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.portfolio-table .cell-currency {
    font-family: var(--font-mono);
    font-weight: 500;
}

.portfolio-table .cell-positive {
    color: var(--color-keep);
}

.portfolio-table .cell-negative {
    color: var(--color-withdraw);
}

.portfolio-table .cell-neutral {
    color: var(--text-secondary);
}

/* Type badge in table */
.type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-accent);
}

.type-badge.type-selic { background: rgba(34, 197, 94, 0.1); color: #4ade80; }
.type-badge.type-ipca { background: rgba(59, 130, 246, 0.1); color: #60a5fa; }
.type-badge.type-pre { background: rgba(245, 158, 11, 0.1); color: #fbbf24; }
.type-badge.type-cdb { background: rgba(168, 85, 247, 0.1); color: #c084fc; }
.type-badge.type-prev { background: rgba(236, 72, 153, 0.1); color: #f472b6; }

/* Decision badges */
.decision-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: default;
}

.decision-keep { background: var(--color-keep-bg); color: var(--color-keep); }
.decision-opportunity { background: var(--color-opportunity-bg); color: var(--color-opportunity); }
.decision-monitor { background: var(--color-monitor-bg); color: var(--color-monitor); }
.decision-wait { background: var(--color-wait-bg); color: var(--color-wait); }
.decision-review { background: var(--color-review-bg); color: var(--color-review); }
.decision-withdraw { background: var(--color-withdraw-bg); color: var(--color-withdraw); }

.decision-tooltip {
    position: relative;
}

.decision-tooltip .tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-modal);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.72rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-secondary);
    white-space: normal;
    width: 220px;
    box-shadow: var(--shadow-modal);
    transition: all 0.15s ease;
    z-index: 50;
    pointer-events: none;
}

.decision-tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    gap: 8px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.9rem;
}

.empty-state .hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.empty-state.hidden {
    display: none;
}

/* ============ LEGEND ============ */
.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
    padding: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-item .decision-badge {
    min-width: 110px;
    justify-content: center;
    flex-shrink: 0;
}

/* ============ REFERENCE TABLES ============ */
.ref-tables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    padding: 20px;
}

.ref-table-block h3 {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-accent);
    margin-bottom: 10px;
}

.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.ref-table th {
    text-align: left;
    padding: 6px 10px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ref-table td {
    padding: 6px 10px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

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

.ref-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-modal);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    width: 95%;
    max-width: 560px;
    box-shadow: var(--shadow-modal);
    transform: translateY(20px) scale(0.97);
    transition: transform 0.25s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

/* ============ FORM ============ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 20px 24px;
}

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

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group.hidden {
    display: none;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group label .optional {
    color: var(--text-muted);
    font-weight: 400;
}

.form-group input,
.form-group select {
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.88rem;
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-group select {
    cursor: pointer;
    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='%239999aa' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border-subtle);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    html { font-size: 13px; }

    .header-content { padding: 12px 16px; }
    .main { padding: 16px; gap: 16px; }
    .indicators-grid { grid-template-columns: 1fr 1fr; padding: 16px; }
    .legend-grid { grid-template-columns: 1fr; }
    .ref-tables-grid { grid-template-columns: 1fr 1fr; }
    .form-grid { grid-template-columns: 1fr; }

    .header-actions .btn span { display: none; }
}

@media (max-width: 480px) {
    .indicators-grid { grid-template-columns: 1fr; }
    .ref-tables-grid { grid-template-columns: 1fr; }
}

/* ============ ANIMATIONS ============ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.portfolio-table tbody tr {
    animation: fadeInUp 0.3s ease forwards;
}

/* Row actions */
.row-actions {
    display: flex;
    gap: 2px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}
