<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}SSR Procurement System{% endblock %} — PT. SSR</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg: #0f1117;
            --bg-card: #1a1d27;
            --bg-input: #13151f;
            --border: #2a2d3e;
            --border-light: #353852;
            --text: #e2e4f0;
            --text-muted: #6b7280;
            --text-dim: #9ca3af;
            --accent: #4f6ef7;
            --accent-hover: #6b84f8;
            --accent-soft: rgba(79,110,247,0.12);
            --green: #22c55e;
            --green-soft: rgba(34,197,94,0.12);
            --yellow: #f59e0b;
            --yellow-soft: rgba(245,158,11,0.12);
            --red: #ef4444;
            --red-soft: rgba(239,68,68,0.12);
            --purple: #a855f7;
            --purple-soft: rgba(168,85,247,0.12);
            --sidebar-w: 260px;
            --radius: 10px;
            --shadow: 0 4px 24px rgba(0,0,0,0.4);
        }

        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

        /* Sidebar */
        .sidebar {
            position: fixed; top: 0; left: 0; bottom: 0;
            width: var(--sidebar-w); background: var(--bg-card);
            border-right: 1px solid var(--border);
            display: flex; flex-direction: column; z-index: 100;
            overflow-y: auto;
        }
        .sidebar-brand {
            padding: 24px 20px 20px;
            border-bottom: 1px solid var(--border);
        }
        .brand-logo {
            display: flex; align-items: center; gap: 10px;
            text-decoration: none;
        }
        .brand-icon {
            width: 36px; height: 36px; background: var(--accent);
            border-radius: 8px; display: flex; align-items: center; justify-content: center;
            font-size: 16px; font-weight: 700; color: white;
        }
        .brand-name { font-size: 15px; font-weight: 700; color: var(--text); }
        .brand-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

        .nav-section { padding: 20px 12px 8px; }
        .nav-label {
            font-size: 10px; font-weight: 600; color: var(--text-muted);
            text-transform: uppercase; letter-spacing: 1px;
            padding: 0 8px; margin-bottom: 6px;
        }
        .nav-item {
            display: flex; align-items: center; gap: 10px;
            padding: 9px 10px; border-radius: 7px;
            text-decoration: none; color: var(--text-dim);
            font-size: 13.5px; font-weight: 500;
            transition: all .15s; margin-bottom: 2px;
        }
        .nav-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
        .nav-item.active { background: var(--accent-soft); color: var(--accent); }
        .nav-icon { width: 18px; text-align: center; opacity: .8; }
        .nav-badge {
            margin-left: auto; background: var(--accent);
            color: white; font-size: 10px; font-weight: 600;
            padding: 1px 7px; border-radius: 20px;
        }

        .sidebar-footer {
            margin-top: auto; padding: 16px;
            border-top: 1px solid var(--border);
        }
        .user-card {
            display: flex; align-items: center; gap: 10px;
            padding: 10px; border-radius: 8px;
            background: rgba(255,255,255,.03);
        }
        .user-avatar {
            width: 32px; height: 32px; border-radius: 50%;
            background: var(--accent); display: flex; align-items: center;
            justify-content: center; font-weight: 600; font-size: 13px; color: white;
            flex-shrink: 0;
        }
        .user-name { font-size: 13px; font-weight: 600; }
        .user-role { font-size: 11px; color: var(--text-muted); }
        .logout-btn {
            margin-left: auto; color: var(--text-muted); text-decoration: none;
            font-size: 16px; padding: 4px; border-radius: 5px;
            transition: color .15s;
        }
        .logout-btn:hover { color: var(--red); }

        /* Main */
        .main { margin-left: var(--sidebar-w); min-height: 100vh; }
        .topbar {
            position: sticky; top: 0; z-index: 50;
            background: rgba(15,17,23,.9); backdrop-filter: blur(12px);
            border-bottom: 1px solid var(--border);
            padding: 14px 32px; display: flex; align-items: center; gap: 16px;
        }
        .page-title { font-size: 16px; font-weight: 600; }
        .page-breadcrumb { font-size: 13px; color: var(--text-muted); }
        .topbar-actions { margin-left: auto; display: flex; gap: 10px; }

        .content { padding: 28px 32px; }

        /* Cards */
        .card {
            background: var(--bg-card); border: 1px solid var(--border);
            border-radius: var(--radius); padding: 24px;
        }
        .card-header {
            display: flex; align-items: center; justify-content: space-between;
            margin-bottom: 20px;
        }
        .card-title { font-size: 15px; font-weight: 600; }

        .stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
        .stat-card {
            background: var(--bg-card); border: 1px solid var(--border);
            border-radius: var(--radius); padding: 20px;
        }
        .stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }
        .stat-value { font-size: 26px; font-weight: 700; }
        .stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
        .stat-icon { font-size: 22px; margin-bottom: 12px; }

        /* Buttons */
        .btn {
            display: inline-flex; align-items: center; gap: 7px;
            padding: 8px 16px; border-radius: 7px; font-size: 13.5px;
            font-weight: 500; cursor: pointer; border: none;
            text-decoration: none; transition: all .15s; font-family: inherit;
        }
        .btn-primary { background: var(--accent); color: white; }
        .btn-primary:hover { background: var(--accent-hover); }
        .btn-secondary { background: rgba(255,255,255,.07); color: var(--text); border: 1px solid var(--border); }
        .btn-secondary:hover { background: rgba(255,255,255,.1); }
        .btn-success { background: var(--green); color: white; }
        .btn-danger { background: var(--red); color: white; }
        .btn-sm { padding: 5px 12px; font-size: 12.5px; }

        /* Badges */
        .badge {
            display: inline-flex; align-items: center; gap: 4px;
            padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
        }
        .badge-success { background: var(--green-soft); color: var(--green); }
        .badge-warning { background: var(--yellow-soft); color: var(--yellow); }
        .badge-danger { background: var(--red-soft); color: var(--red); }
        .badge-info { background: var(--accent-soft); color: var(--accent); }
        .badge-purple { background: var(--purple-soft); color: var(--purple); }
        .badge-secondary { background: rgba(255,255,255,.07); color: var(--text-dim); }

        /* Table */
        .table-wrap { overflow-x: auto; }
        table { width: 100%; border-collapse: collapse; }
        th {
            text-align: left; font-size: 11.5px; font-weight: 600;
            color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
            padding: 10px 14px; border-bottom: 1px solid var(--border);
        }
        td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
        tr:last-child td { border-bottom: none; }
        tr:hover td { background: rgba(255,255,255,.02); }
        .text-right { text-align: right; }
        .text-center { text-align: center; }
        .font-mono { font-family: 'JetBrains Mono', monospace; }

        /* Forms */
        .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
        .form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
        .form-group { display: flex; flex-direction: column; gap: 6px; }
        .form-group.full { grid-column: 1/-1; }
        label { font-size: 12.5px; font-weight: 500; color: var(--text-dim); }
        input, select, textarea {
            background: var(--bg-input); border: 1px solid var(--border);
            border-radius: 7px; padding: 9px 13px; color: var(--text);
            font-size: 13.5px; font-family: inherit; outline: none;
            transition: border-color .15s;
        }
        input:focus, select:focus, textarea:focus { border-color: var(--accent); }
        textarea { resize: vertical; min-height: 90px; }
        select option { background: var(--bg-card); }

        /* Alerts */
        .alert {
            padding: 12px 16px; border-radius: 8px; font-size: 13.5px;
            margin-bottom: 16px; display: flex; align-items: center; gap: 10px;
        }
        .alert-success { background: var(--green-soft); color: var(--green); border: 1px solid rgba(34,197,94,.2); }
        .alert-danger { background: var(--red-soft); color: var(--red); border: 1px solid rgba(239,68,68,.2); }
        .alert-warning { background: var(--yellow-soft); color: var(--yellow); border: 1px solid rgba(245,158,11,.2); }
        .alert-info { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(79,110,247,.2); }

        /* Progress bar */
        .progress-bar { background: var(--border); border-radius: 99px; height: 6px; overflow: hidden; }
        .progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
        .progress-fill.warn { background: var(--yellow); }
        .progress-fill.danger { background: var(--red); }

        /* Utils */
        .flex { display: flex; }
        .items-center { align-items: center; }
        .gap-2 { gap: 8px; }
        .gap-3 { gap: 12px; }
        .mt-4 { margin-top: 16px; }
        .mb-4 { margin-bottom: 16px; }
        .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
        .text-green { color: var(--green); }
        .text-red { color: var(--red); }
        .text-yellow { color: var(--yellow); }
        .text-muted { color: var(--text-muted); }
        .text-accent { color: var(--accent); }
        .fw-600 { font-weight: 600; }
        .fs-13 { font-size: 13px; }

        /* Divider */
        .divider { height: 1px; background: var(--border); margin: 20px 0; }

        /* Item rows for dynamic forms */
        .item-row { display: grid; gap: 10px; align-items: end; padding: 14px; background: rgba(255,255,255,.02); border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--border); }
        .item-row-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
        .remove-row { background: none; border: none; color: var(--red); cursor: pointer; font-size: 18px; }

        @media (max-width: 768px) {
            .sidebar { transform: translateX(-100%); }
            .main { margin-left: 0; }
            .stat-grid { grid-template-columns: 1fr 1fr; }
            .form-grid { grid-template-columns: 1fr; }
        }
    </style>
    {% block head %}{% endblock %}
</head>
<body>

{% if current_user.is_authenticated %}
<aside class="sidebar">
    <div class="sidebar-brand">
        <a href="{{ url_for('dashboard.index') }}" class="brand-logo">
            <div class="brand-icon">SA</div>
            <div>
                <div class="brand-name">SSR Procurement System</div>
                <div class="brand-sub">PT. SSR</div>
            </div>
        </a>
    </div>

    <nav class="nav-section">
        <div class="nav-label">Utama</div>
        <a href="{{ url_for('dashboard.index') }}" class="nav-item {% if request.endpoint == 'dashboard.index' %}active{% endif %}">
            <span class="nav-icon">📊</span> Dashboard
        </a>
    </nav>

    <nav class="nav-section">
        <div class="nav-label">Proyek</div>
        <a href="{{ url_for('projects.index') }}" class="nav-item {% if 'projects.' in request.endpoint %}active{% endif %}">
            <span class="nav-icon">🏗️</span> Manajemen Proyek
        </a>
    </nav>

    <nav class="nav-section">
        <div class="nav-label">Pengadaan</div>
        <a href="{{ url_for('procurement.pr_list') }}" class="nav-item {% if request.endpoint in ['procurement.pr_list','procurement.pr_create','procurement.pr_detail'] %}active{% endif %}">
            <span class="nav-icon">📋</span> Purchase Request
        </a>
        <a href="{{ url_for('procurement.po_list') }}" class="nav-item {% if request.endpoint in ['procurement.po_list','procurement.po_create','procurement.po_detail'] %}active{% endif %}">
            <span class="nav-icon">📦</span> Purchase Order
        </a>
        <a href="{{ url_for('procurement.vendor_list') }}" class="nav-item {% if 'vendor' in request.endpoint %}active{% endif %}">
            <span class="nav-icon">🏢</span> Vendor
        </a>
    </nav>

    <nav class="nav-section">
        <div class="nav-label">Akuntansi (PSAK 72)</div>
        <a href="{{ url_for('accounting.laporan_project_cost') }}" class="nav-item {% if request.endpoint == 'accounting.laporan_project_cost' %}active{% endif %}">
            <span class="nav-icon">💰</span> Biaya Proyek
        </a>
        <a href="{{ url_for('accounting.laporan_revenue') }}" class="nav-item {% if request.endpoint == 'accounting.laporan_revenue' %}active{% endif %}">
            <span class="nav-icon">📈</span> Pengakuan Pendapatan
        </a>
        <a href="{{ url_for('accounting.laporan_budget_vs_actual') }}" class="nav-item {% if request.endpoint == 'accounting.laporan_budget_vs_actual' %}active{% endif %}">
            <span class="nav-icon">⚖️</span> Budget vs Aktual
        </a>
    </nav>

    <nav class="nav-section">
        <div class="nav-label">Dokumen</div>
        <a href="{{ url_for('documents.index') }}" class="nav-item {% if 'documents.' in request.endpoint %}active{% endif %}">
            <span class="nav-icon">📁</span> Manajemen Dokumen
        </a>
    </nav>

    <div class="sidebar-footer">
        <div class="user-card">
            <div class="user-avatar">{{ current_user.full_name[0] }}</div>
            <div>
                <div class="user-name">{{ current_user.full_name.split()[0] }}</div>
                <div class="user-role">{{ current_user.role|title }}</div>
            </div>
            <a href="{{ url_for('auth.logout') }}" class="logout-btn" title="Logout">⏻</a>
        </div>
    </div>
</aside>
{% endif %}

<main class="{% if current_user.is_authenticated %}main{% endif %}">
    {% if current_user.is_authenticated %}
    <div class="topbar">
        <div>
            <div class="page-breadcrumb">{% block breadcrumb %}SiAkun Pengadaan{% endblock %}</div>
            <div class="page-title">{% block page_title %}Dashboard{% endblock %}</div>
        </div>
        <div class="topbar-actions">{% block topbar_actions %}{% endblock %}</div>
    </div>
    {% endif %}

    <div class="{% if current_user.is_authenticated %}content{% endif %}">
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for cat, msg in messages %}
            <div class="alert alert-{{ cat }}">
                <span>{% if cat == 'success' %}✓{% elif cat == 'danger' %}✗{% elif cat == 'warning' %}⚠{% else %}ℹ{% endif %}</span>
                {{ msg }}
            </div>
            {% endfor %}
        {% endif %}
        {% endwith %}

        {% block content %}{% endblock %}
    </div>
</main>

<script>
function formatRupiah(input) {
    let val = input.value.replace(/[^0-9]/g, '');
    input.value = val ? parseInt(val).toLocaleString('id-ID') : '';
}
function getRawValue(val) {
    return val.replace(/\./g, '').replace(/,/g, '');
}
</script>
{% block scripts %}{% endblock %}
</body>
</html>
