:root {
    --ink: #0f172a;
    --ink-soft: #64748b;
    --paper: #f1f5f9;
    --panel: #ffffff;
    --line: #e2e8f0;
    --accent: #0f766e;
    --accent-dark: #0b5c56;
    --accent-soft: #ccfbf1;
    --sidebar: #0b1220;
    --sidebar-2: #162033;
    --ok: #047857;
    --danger: #b91c1c;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
    letter-spacing: -.01em;
}

.app-shell { min-height: 100vh; display: flex; }
.app-sidebar {
    width: 268px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--sidebar);
    color: #e2e8f0;
    padding: 1.15rem 0.95rem;
}
.sidebar-brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.2rem 0.45rem 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand strong {
    display: block;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.25;
    color: #fff;
}
.sidebar-brand small {
    color: #94a3b8;
    font-size: 0.75rem;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.sidebar-logo { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: 10px; }
.sidebar-mark {
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--accent); color: #fff; display: grid; place-items: center;
    font-weight: 700; letter-spacing: .04em; font-size: 0.85rem;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding-top: 1rem;
}
.sidebar-spacer {
    flex: 1 1 auto;
    min-height: 1.25rem;
    margin: 0.55rem 0 0.35rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #cbd5e1;
    text-decoration: none;
    padding: 0.58rem 0.75rem;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.94rem;
}
.sidebar-nav svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}
.sidebar-nav a:hover { background: var(--sidebar-2); color: #fff; }
.sidebar-nav a.active, .sidebar-nav .nav-parent.active {
    background: rgba(15, 118, 110, .22);
    color: #fff;
}
.nav-group { display: flex; flex-direction: column; gap: 0.15rem; }
.nav-sub {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.15rem 0 0.25rem 1.05rem;
    margin-left: 0.85rem;
    border-left: 1px solid rgba(148, 163, 184, .25);
}
.nav-sub a {
    padding: 0.42rem 0.7rem;
    font-size: 0.88rem;
    color: #94a3b8;
}
.nav-sub a.active {
    background: var(--sidebar-2);
    color: #fff;
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 1rem 1.5rem;
    background: rgba(255,255,255,.86);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-kicker {
    margin: 0 0 0.1rem;
    font-size: 0.72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    font-weight: 600;
}
.topbar-title h1 { margin: 0; font-size: 1.28rem; font-weight: 650; letter-spacing: -.02em; }
.topbar-user { display: flex; align-items: center; gap: 0.7rem; color: var(--ink-soft); font-weight: 500; }
.user-name { font-size: 0.9rem; color: var(--ink); }
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent-dark);
    display: grid; place-items: center; font-size: 0.75rem; font-weight: 700;
}
.btn-menu {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
}
.app-content { padding: 1.4rem 1.5rem 2rem; }

.btn { border-radius: 8px; font-weight: 550; }
.btn-accent, .btn-accent:hover, .btn-accent:focus {
    background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-outline-secondary { border-color: #cbd5e1; color: #334155; }
.btn-outline-secondary:hover { background: #f8fafc; border-color: #94a3b8; color: var(--ink); }

.form-control, .form-select {
    border-radius: 8px;
    border-color: #d0d7e2;
    padding: 0.55rem 0.75rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .16);
}
.form-label { font-weight: 550; font-size: 0.86rem; color: #334155; margin-bottom: 0.3rem; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.2rem 1.25rem;
    box-shadow: var(--shadow);
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.panel-head h2 { margin: 0; font-size: 1.02rem; font-weight: 650; }
.empty-note, .form-hint { color: var(--ink-soft); }
.search-inline { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ink-soft);
    font-weight: 650;
    border-bottom-color: var(--line);
    white-space: nowrap;
}
.table thead a { color: inherit; text-decoration: none; }
.table thead a:hover { color: var(--accent); }
.table td { vertical-align: middle; color: #1e293b; }
.table-hover > tbody > tr:hover { --bs-table-hover-bg: #f8fafc; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; margin-bottom: 1.1rem; }
.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.05rem 1.15rem;
    box-shadow: var(--shadow);
}
.stat-card span { color: var(--ink-soft); display: block; font-size: 0.78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.stat-card strong { font-size: 1.85rem; font-weight: 700; letter-spacing: -.03em; }

.thumb { width: 72px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #f8fafc; }
.logo-preview { max-height: 64px; max-width: 180px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
.pager { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 1rem; }

.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
.meta-grid span { display: block; color: var(--ink-soft); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 0.2rem; }
.view-frame { text-align: center; }
.view-frame img { max-width: 100%; height: auto; border-radius: 10px; }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at top right, rgba(15, 118, 110, .28), transparent 32%),
        linear-gradient(160deg, #0b1220 0%, #111827 55%, #0f172a 100%);
}
.login-wrap { width: min(440px, 92vw); }
.login-card {
    background: #fff;
    border-radius: 20px;
    padding: 2.1rem 2rem 2rem;
    box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand img { max-height: 58px; margin-bottom: 0.7rem; }
.login-brand h1 { font-size: 1.3rem; margin: 0.45rem 0 0.25rem; font-weight: 700; }
.login-brand p { color: var(--ink-soft); margin: 0; font-size: 0.92rem; }
.login-brand .sidebar-mark { margin: 0 auto 0.7rem; }

.editor-toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.8rem; }
.tool-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.tool-group label { font-size: 0.8rem; color: var(--ink-soft); display: flex; align-items: center; gap: 0.3rem; }
.tool-group input[type="number"], .tool-group select { height: 32px; border: 1px solid var(--line); border-radius: 6px; padding: 0 0.35rem; }
.editor-stage {
    overflow: auto; background: #e2e8f0; border-radius: 12px; min-height: 420px;
    max-height: calc(100vh - 260px);
}
#diagramCanvas { display: block; }

.dropzone {
    display: block;
    min-height: 240px;
    border: 2px dashed #94a3b8;
    border-radius: 16px;
    background: #f8fafc;
    padding: 1.7rem 1.2rem;
    cursor: pointer;
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.dropzone:hover, .dropzone.is-dragover {
    border-color: var(--accent);
    background: #f0fdfa;
    box-shadow: inset 0 0 0 3px rgba(15, 118, 110, .08);
}
.dropzone-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}
.dropzone-body {
    min-height: 196px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.35rem;
}
.dropzone-body strong { font-size: 1.12rem; font-weight: 650; }
.dropzone-body span { color: var(--ink-soft); }
.dropzone-body em { font-style: normal; font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.35rem; }
.dropzone-file {
    min-height: 196px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    text-align: left;
}
.dropzone-file[hidden] { display: none; }
.dropzone-preview {
    width: 120px;
    height: 88px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.dropzone-file strong { display: block; }
.dropzone-file span { color: var(--ink-soft); font-size: 0.85rem; }

.alert { border-radius: 12px; border: 0; }
.badge { font-weight: 600; letter-spacing: .02em; }

@media (min-width: 992px) {
    .app-sidebar.offcanvas-lg {
        position: static;
        transform: none;
        visibility: visible;
        width: 268px;
        min-height: 100vh;
        height: auto;
        align-self: stretch;
        background: var(--sidebar);
        border-right: 1px solid #0a101a;
    }
}
@media (max-width: 991px) {
    .app-shell { display: block; }
    .app-sidebar { width: 288px; }
    .stat-grid, .meta-grid { grid-template-columns: 1fr 1fr; }
    .user-name { display: none; }
}
@media (max-width: 640px) {
    .stat-grid, .meta-grid { grid-template-columns: 1fr; }
    .panel-head { flex-direction: column; align-items: stretch; }
    .app-content { padding: 1rem; }
}
