/* ============================================================
   Finans Takip Paneli — App CSS
   Dark Theme, Modern UI
   ============================================================ */

/* ── Variables ───────────────────────────────────────────── */
:root {
    --bg-primary:    #0d1520;
    --bg-secondary:  #111c2b;
    --bg-card:       #152032;
    --bg-card-hover: #1a2840;
    --bg-input:      #0f1a27;
    --border:        rgba(255,255,255,0.07);
    --border-focus:  #3b82f6;

    --text-primary:  #e2e8f0;
    --text-secondary:#94a3b8;
    --text-muted:    #475569;

    --accent-blue:   #3b82f6;
    --accent-green:  #10b981;
    --accent-red:    #ef4444;
    --accent-yellow: #f59e0b;
    --accent-purple: #8b5cf6;
    --accent-teal:   #14b8a6;

    --sidebar-width: 240px;
    --topbar-height: 60px;

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 16px;

    --shadow:    0 4px 20px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);

    --transition: all 0.2s ease;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Layout ──────────────────────────────────────────────── */
.app-body {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0; top: 0;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition);
}

.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .sidebar-logo span,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .user-details,
.sidebar.collapsed .nav-divider { display: none; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-card); }

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.625rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
    overflow: hidden;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.nav-item svg { flex-shrink: 0; }

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.sidebar-footer {
    padding: 0.875rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info { display: flex; align-items: center; gap: 0.625rem; flex: 1; min-width: 0; }

.user-avatar {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.875rem;
    flex-shrink: 0;
}

.user-details { min-width: 0; }
.user-name  { display: block; font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { display: block; font-size: 0.7rem; color: var(--text-muted); }

.btn-logout {
    background: none; border: none;
    color: var(--text-muted); padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}
.btn-logout:hover { color: var(--accent-red); background: rgba(239,68,68,0.1); }

/* ── Main Content ────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}

.sidebar.collapsed ~ .main-content { margin-left: 60px; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.page-title { font-size: 1rem; font-weight: 600; }

.last-update {
    display: flex; align-items: center; gap: 0.375rem;
    font-size: 0.75rem; color: var(--text-muted);
}

.mobile-menu-btn {
    display: none;
    background: none; border: none;
    color: var(--text-secondary); padding: 4px;
}

#pageContent { flex: 1; padding: 1.5rem; overflow-x: hidden; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: var(--transition);
}
.stat-card:hover { border-color: rgba(59,130,246,0.3); background: var(--bg-card-hover); }

.stat-card-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
    display: flex; align-items: center; gap: 0.4rem;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.25rem;
}

.stat-card-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.badge-positive { color: var(--accent-green); }
.badge-negative { color: var(--accent-red); }
.badge-neutral  { color: var(--text-secondary); }

/* ── Grid Layouts ────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.chart-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; margin-bottom: 1rem; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

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

.table thead th {
    background: rgba(255,255,255,0.03);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table tbody td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: rgba(255,255,255,0.02); }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }

/* Sıralanabilir tablo başlıkları */
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s, color 0.2s;
}

.table thead th.sortable:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

/* ── Badges / Tags ───────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-stock  { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-tefas  { background: rgba(139,92,246,0.15); color: #a78bfa; }
.badge-bes    { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-fx     { background: rgba(20,184,166,0.15); color: #2dd4bf; }
.badge-metal  { background: rgba(234,179,8,0.15);  color: #facc15; }

.badge-buy      { background: rgba(16,185,129,0.15); color: #34d399; }
.badge-sell     { background: rgba(239,68,68,0.15);  color: #f87171; }
.badge-dividend { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-split    { background: rgba(245,158,11,0.15); color: #fbbf24; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary   { background: var(--accent-blue); color: #fff; }
.btn-primary:hover   { background: #2563eb; transform: translateY(-1px); }
.btn-success   { background: var(--accent-green); color: #fff; }
.btn-success:hover   { background: #059669; }
.btn-danger    { background: var(--accent-red); color: #fff; }
.btn-danger:hover    { background: #dc2626; }
.btn-secondary { background: rgba(255,255,255,0.06); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,0.1); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn-icon { padding: 0.5rem; }
.w-full { width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-control {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.625rem 0.875rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s;
    outline: none;
}
.form-control:focus { border-color: var(--border-focus); }
.form-control::placeholder { color: var(--text-muted); }

select.form-control option { background: #1a2840; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Safari: SVG ve diğer alt elementlerin tıklamayı yutmasını önle */
.modal-close * { pointer-events: none; }
.btn-logout *   { pointer-events: none; }
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    z-index: 210;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}
.modal-lg { max-width: 760px; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.25rem;
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
    background: none; border: none;
    color: var(--text-muted); padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-secondary); }
.modal-footer {
    display: flex; justify-content: flex-end; gap: 0.75rem;
    margin-top: 1.5rem; padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* ── Toast ───────────────────────────────────────────────── */
.toast-container {
    position: fixed; bottom: 1.5rem; right: 1.5rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    z-index: 300;
}

.toast {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 0.875rem;
    min-width: 280px;
    max-width: 380px;
    animation: toastIn 0.3s ease;
}
.toast-success { border-left: 3px solid var(--accent-green); }
.toast-error   { border-left: 3px solid var(--accent-red); }
.toast-info    { border-left: 3px solid var(--accent-blue); }
.toast-warning { border-left: 3px solid var(--accent-yellow); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ── Loading ─────────────────────────────────────────────── */
.loading-screen {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 400px; gap: 1rem;
    color: var(--text-muted);
}

.loading-spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.7s linear infinite; }

/* ── Paging ──────────────────────────────────────────────── */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 1rem 0;
}

.page-btn {
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-secondary); padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm); font-size: 0.8rem;
    cursor: pointer; transition: var(--transition);
    min-width: 32px;
}
.page-btn:hover   { border-color: var(--accent-blue); color: var(--accent-blue); }
.page-btn.active  { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Period Tabs ─────────────────────────────────────────── */
.period-tabs {
    display: flex; gap: 4px;
    background: rgba(255,255,255,0.04);
    border-radius: var(--radius);
    padding: 3px;
}

.period-tab {
    background: none; border: none;
    color: var(--text-muted); padding: 0.3rem 0.75rem;
    border-radius: 7px; font-size: 0.78rem;
    font-weight: 600; cursor: pointer; transition: var(--transition);
}
.period-tab.active { background: var(--accent-blue); color: #fff; }
.period-tab:hover:not(.active) { color: var(--text-primary); }

/* ── Section Headers ─────────────────────────────────────── */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.section-title { font-size: 0.9rem; font-weight: 700; }

/* ── Donut Chart Label ───────────────────────────────────── */
.chart-legend { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.legend-item  { display: flex; align-items: center; justify-content: space-between; font-size: 0.8rem; }
.legend-dot   { width: 10px; height: 10px; border-radius: 50%; margin-right: 0.5rem; flex-shrink: 0; }
.legend-label { display: flex; align-items: center; color: var(--text-secondary); }
.legend-value { color: var(--text-primary); font-weight: 600; }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state svg { margin: 0 auto 1rem; opacity: 0.3; }
.empty-state h3 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-secondary); }
.empty-state p  { font-size: 0.8rem; }

/* ── Tablar (portfolio detail) ───────────────────────────── */
.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab-btn {
    background: none; border: none;
    color: var(--text-muted); padding: 0.6rem 1rem;
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    border-bottom: 2px solid transparent; transition: var(--transition);
    margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }
.tab-btn:hover:not(.active) { color: var(--text-primary); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .chart-grid { grid-template-columns: 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .mobile-menu-btn { display: flex; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    #pageContent { padding: 1rem; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .modal { margin: 1rem; }
}

/* ── 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); }

/* ── Autocomplete ────────────────────────────────────────── */
.autocomplete-wrapper { position: relative; }
.autocomplete-list {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
    max-height: 240px; overflow-y: auto;
    margin-top: 2px;
}
.autocomplete-item {
    padding: 0.625rem 0.875rem;
    cursor: pointer; font-size: 0.85rem;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: var(--transition);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: rgba(255,255,255,0.04); }
.autocomplete-symbol { font-weight: 700; }
.autocomplete-name   { color: var(--text-muted); font-size: 0.78rem; max-width: 55%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Profit/Loss colors ──────────────────────────────────── */
.positive { color: var(--accent-green) !important; }
.negative { color: var(--accent-red)   !important; }
.neutral  { color: var(--text-secondary) !important; }

/* ── Number formatting ───────────────────────────────────── */
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
