/* =============================================================
   Tradecore - CSS Stylesheet
   Modern, clean, industrieel ontwerp
   ============================================================= */

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

:root {
    --color-primary: #1a5276;
    --color-primary-light: #2471a3;
    --color-primary-dark: #0e3a54;
    --color-accent: #e67e22;
    --color-accent-light: #f39c12;
    --color-link: var(--color-accent);
    --color-heading: var(--color-accent);
    --color-success: #27ae60;
    --color-danger: #e74c3c;
    --color-warning: #f39c12;

    --color-bg: #f4f6f8;
    --color-white: #ffffff;
    --color-text: #1c2833;
    --color-text-muted: #5d6d7e;
    --color-border: #dce1e6;

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 84px;
    --sidebar-bg: #1a5276;
    --sidebar-text: #d5e8f4;
    --sidebar-active: #e67e22;

    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --transition: 150ms ease;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

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

a {
    color: var(--color-link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

code {
    background: #eaecee;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.87em;
}

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

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.1rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar-toggle {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    min-width: 0;
    flex: 1;
}

.sidebar-logo-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity var(--transition);
}

.nav-text {
    transition: opacity var(--transition);
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    color: var(--sidebar-text);
    font-size: 0.9rem;
    text-decoration: none;
    transition: background var(--transition);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-weight: 600;
}

.nav-item.active svg {
    color: var(--sidebar-active);
}

.nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0.75rem 0;
}

.nav-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0 0.75rem;
    margin-bottom: 0.25rem;
    opacity: 0.5;
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-email {
    font-size: 0.8rem;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    font-size: 0.7rem;
    opacity: 0.6;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem 2.5rem;
    min-height: 100vh;
}

.sync-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.55rem;
    min-height: 2.25rem;
    margin-bottom: 1rem;
    color: var(--color-text-muted);
    font-size: 0.84rem;
}

.sync-status-dot {
    width: 0.62rem;
    height: 0.62rem;
    border-radius: 999px;
    background: #1e8449;
    box-shadow: 0 0 0 3px rgba(30, 132, 73, 0.12);
    flex: 0 0 auto;
}

.sync-status.is-offline .sync-status-dot {
    background: #c0392b;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}

.sync-status.is-syncing .sync-status-dot {
    background: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.16);
}

.sync-status-network {
    font-weight: 700;
    color: var(--color-text);
}

.sync-status-count {
    white-space: nowrap;
}

.sync-status-button {
    min-width: 4.2rem;
}

.sync-status-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

body.sidebar-collapsed .sidebar,
html.sidebar-collapsed-early body .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main-content,
html.sidebar-collapsed-early body .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar-header,
html.sidebar-collapsed-early body .sidebar-header {
    padding: 1rem 0.75rem;
}

body.sidebar-collapsed .sidebar-brand,
html.sidebar-collapsed-early body .sidebar-brand {
    flex-direction: column;
    gap: 0.5rem;
}

body.sidebar-collapsed .sidebar-toggle svg,
html.sidebar-collapsed-early body .sidebar-toggle svg {
    transform: rotate(180deg);
}

body.sidebar-collapsed .sidebar-logo,
html.sidebar-collapsed-early body .sidebar-logo {
    justify-content: center;
    flex: unset;
}

body.sidebar-collapsed .sidebar-logo-text,
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .user-info,
html.sidebar-collapsed-early body .sidebar-logo-text,
html.sidebar-collapsed-early body .nav-text,
html.sidebar-collapsed-early body .nav-label,
html.sidebar-collapsed-early body .user-info {
    display: none;
}

body.sidebar-collapsed .sidebar-nav,
body.sidebar-collapsed .sidebar-footer,
html.sidebar-collapsed-early body .sidebar-nav,
html.sidebar-collapsed-early body .sidebar-footer {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

body.sidebar-collapsed .nav-item,
body.sidebar-collapsed .sidebar-logout,
html.sidebar-collapsed-early body .nav-item,
html.sidebar-collapsed-early body .sidebar-logout {
    justify-content: center;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
}

body.sidebar-collapsed .sidebar-user,
html.sidebar-collapsed-early body .sidebar-user {
    justify-content: center;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-heading);
    line-height: 1.3;
}

.page-subtitle {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.back-link {
    display: inline-block;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 0.4rem;
}

.back-link:hover {
    color: var(--color-accent);
}

/* --- Cards --- */
.card {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

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

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-heading);
}

.card-body {
    padding: 1.5rem;
}

/* --- Error Pages --- */
.error-page {
    min-height: calc(100vh - 4rem);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.error-panel {
    width: min(620px, 100%);
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-top: 5px solid var(--color-accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2rem;
    display: grid;
    gap: 1.2rem;
}

.error-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--color-primary) 12%, white);
    color: var(--color-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.error-kicker {
    color: var(--color-accent);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.25rem;
}

.error-copy h1 {
    color: var(--color-heading);
    font-size: 1.55rem;
    line-height: 1.25;
    margin-bottom: 0.4rem;
}

.error-copy p {
    color: var(--color-text-muted);
    max-width: 46rem;
}

.error-actions {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
}

/* --- KPI Grid --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon-blue { background: #eaf2f8; color: var(--color-primary); }
.kpi-icon-amber { background: #fef5e7; color: var(--color-accent); }
.kpi-icon-green { background: #e8f8f0; color: var(--color-success); }
.kpi-icon-steel { background: #ebedef; color: #5d6d7e; }

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}

/* --- Detail Grid --- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.25rem;
    padding: 1.25rem 0;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    font-weight: 600;
}

.detail-value {
    font-size: 1rem;
    font-weight: 500;
}

/* --- Tables --- */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid var(--color-border);
}

.table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
    vertical-align: middle;
}

.table tbody tr:hover {
    background: #f8f9fa;
}

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

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: #e8f8f0; color: #1e8449; }
.badge-danger { background: #fdedec; color: #c0392b; }
.badge-primary { background: #eaf2f8; color: var(--color-primary); }
.badge-muted { background: #ebedef; color: #5d6d7e; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
    font-family: inherit;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-light);
}

.btn-outline {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text);
}

.btn-outline:hover {
    background: var(--color-bg);
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border: none;
    padding: 0.4rem 0.75rem;
}

.btn-ghost:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.4rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-white);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 82, 118, 0.12);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin-top: 0.3rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}

/* --- Flash Messages --- */
.flash-messages {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.flash-messages:empty {
    display: none;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flash-success {
    background: #e8f8f0;
    color: #1e8449;
    border: 1px solid #a9dfbf;
}

.flash-error {
    background: #fdedec;
    color: #c0392b;
    border: 1px solid #f5b7b1;
}

.flash-info {
    background: #eaf2f8;
    color: var(--color-primary);
    border: 1px solid #aed6f1;
}

.flash-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0;
    line-height: 1;
}

.flash-close:hover {
    opacity: 1;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* --- Login Page --- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
    padding: 1rem;
}

.login-card {
    background: var(--color-white);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    margin-bottom: 0.75rem;
    color: var(--color-heading);
}

.login-logo img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

.login-header p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.login-form .form-group {
    margin-bottom: 1rem;
}

.login-form .btn {
    margin-top: 0.5rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        display: flex;
        width: var(--sidebar-width);
    }

    .main-content {
        margin-left: var(--sidebar-width);
        padding: 1.25rem;
    }

    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-collapsed-width);
    }

    body.sidebar-collapsed .main-content {
        margin-left: var(--sidebar-collapsed-width);
    }

    .page-header {
        flex-direction: column;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .detail-grid {
        grid-template-columns: 1fr 1fr;
    }

    .table {
        font-size: 0.82rem;
    }

    .table th,
    .table td {
        padding: 0.6rem 0.5rem;
    }
}

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

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .header-actions {
        flex-direction: column;
        width: 100%;
    }

    .header-actions .btn {
        width: 100%;
    }
}
