:root {
    --bg:        #f4f6f8;
    --surface:   #ffffff;
    --border:    #e2e6ea;
    --text:      #1f2933;
    --muted:     #6b7681;
    --primary:   #17497a;
    --primary-d: #0f3355;
    --danger:    #b0322b;
    --ok:        #2e7d46;
    --soon:      #b8860b;
    --overdue:   #b0322b;
    --radius:    10px;
    --shadow:    0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
    --sidebar-w: 250px;
    --topbar-h:  58px;
    font-synthesis: none;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14.5px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .2rem; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* ---------- Top bar ---------- */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-left { width: var(--sidebar-w); }
.topbar-title { font-weight: 700; color: var(--primary); letter-spacing: .2px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.topbar-right .user { color: var(--muted); font-size: .85rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.search { position: relative; }
.search input {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    font-size: .9rem;
}
.search input:focus { outline: 2px solid var(--primary); border-color: var(--primary); background:#fff; }

.search-results {
    position: absolute;
    top: 110%; left: 0; right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-height: 320px; overflow-y: auto;
    display: none; z-index: 40;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: .5rem .7rem; border-bottom: 1px solid var(--border); color: var(--text); }
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover { background: var(--bg); text-decoration: none; }
.search-results .sr-cat { color: var(--muted); font-size: .78rem; }

.lang-switch a, .login-langs a {
    font-size: .78rem; color: var(--muted); padding: .15rem .35rem; border-radius: 5px;
}
.lang-switch a.active, .login-langs a.active { background: var(--primary); color: #fff; }

/* ---------- Layout ---------- */
.layout { display: flex; align-items: stretch; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: .75rem;
}
.sidebar-head { text-transform: uppercase; font-size: .72rem; letter-spacing: .06em; color: var(--muted); padding: .3rem .5rem .5rem; }
.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
    padding: .5rem .6rem; border-radius: 7px; color: var(--text); font-size: .92rem;
}
.cat-item:hover { background: var(--bg); text-decoration: none; }
.cat-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.content { flex: 1 1 auto; padding: 1.25rem 1.5rem; min-width: 0; }

/* ---------- Flash ---------- */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.flash-ok { background: #e7f4ec; color: var(--ok); border: 1px solid #bfe3cc; }
.flash-error { background: #fbeaea; color: var(--danger); border: 1px solid #f0c7c5; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .8rem; border-radius: 8px; font-size: .88rem; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; text-decoration: none; line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); color:#fff; }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--danger); border-color: #e6b7b4; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-xs { padding: .2rem .45rem; font-size: .8rem; }

/* ---------- List / cards ---------- */
.list-head { display: flex; align-items: baseline; gap: .75rem; margin-bottom: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .85rem .95rem; box-shadow: var(--shadow); color: var(--text); display: flex; flex-direction: column; gap: .4rem;
}
.card:hover { text-decoration: none; border-color: var(--primary); box-shadow: 0 3px 10px rgba(16,24,40,.1); }
.card-top { display: flex; align-items: center; justify-content: space-between; }
.card-cat { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.card-title { font-weight: 700; font-size: 1rem; }
.card-meta { font-size: .82rem; color: var(--muted); }
.tag { background: var(--primary); color: #fff; font-size: .68rem; padding: .1rem .35rem; border-radius: 4px; font-weight: 700; }
.empty-list, .empty { color: var(--muted); }

/* ---------- Detail ---------- */
.detail { max-width: 960px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.detail-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.crumb { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: .1rem 2rem; margin: 0; }
.fields > div { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px dashed var(--border); }
.fields > div.wide { grid-column: 1 / -1; flex-direction: column; }
.fields dt { color: var(--muted); font-size: .85rem; margin: 0; }
.fields dd { margin: 0; font-weight: 600; text-align: right; }
.fields > div.wide dd { text-align: left; font-weight: 400; }

.pill { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--bg); color: var(--muted); }
.pill-ok { background: #e7f4ec; color: var(--ok); }

.is-ok { color: var(--ok); }
.is-soon { color: var(--soon); font-weight: 700; }
.is-overdue { color: var(--overdue); font-weight: 700; }

/* ---------- Documents / tree ---------- */
.docs .docs-actions { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.inline-form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.inline-form.tiny { gap: .3rem; }
.inline-form input[type=text] { padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 6px; }

.tree { display: flex; flex-direction: column; gap: .15rem; }
.doc-row { display: grid; grid-template-columns: 22px 1fr auto auto 22px; align-items: center; gap: .6rem; padding: .4rem .3rem; border-radius: 6px; }
.doc-row:hover { background: var(--bg); }
.doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-date, .doc-size { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.doc-del { margin: 0; }
.link-danger { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .9rem; }
.link-danger:hover { color: var(--danger); }

.folder { border-left: 2px solid var(--border); margin: .3rem 0 .3rem .3rem; padding-left: .5rem; }
.folder > summary { display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .35rem .2rem; font-weight: 600; list-style: none; }
.folder > summary::-webkit-details-marker { display: none; }
.folder-name { flex: 1; }
.folder-tools { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.folder-body { padding-left: .7rem; }
.mini-upload { font-size: .78rem; color: var(--primary); cursor: pointer; }
.mini-upload input { display: none; }

/* File-type icons (simple CSS squares w/ letters via ::before) */
.doc-icon { width: 20px; height: 20px; border-radius: 4px; display: inline-block; position: relative; background: var(--muted); }
.doc-icon::before { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .62rem; font-weight: 700; }
.icon-image { background: #2e7d46; } .icon-image::before { content: "IMG"; }
.icon-pdf   { background: #b0322b; } .icon-pdf::before   { content: "PDF"; }
.icon-word  { background: #2b579a; } .icon-word::before  { content: "W"; }
.icon-file  { background: #6b7681; } .icon-file::before  { content: "•"; }
.icon-folder{ background: #d9a441; } .icon-folder::before{ content: "▸"; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.wide { grid-column: 1 / -1; }
.field > span, .field-label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.field input[type=text], .field input[type=email], .field input[type=date], .field select, .field textarea {
    padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 7px; font-size: .92rem; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.field.checkbox { flex-direction: row; align-items: center; gap: .5rem; }
.field.checkbox span { color: var(--text); font-weight: 500; }
.wv-dependent { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: .9rem; background: var(--bg); border-radius: 8px; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }
.form-actions.between { justify-content: space-between; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg,#17497a,#0f3355); }
.login-card { background: #fff; border-radius: 14px; padding: 2.2rem; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.25); text-align: center; }
.login-card h1 { color: var(--primary); margin-bottom: .3rem; }
.login-card .btn { margin-top: 1rem; }
.login-langs { margin-top: 1.2rem; display: flex; gap: .4rem; justify-content: center; }

@media (max-width: 820px) {
    .topbar-left { width: auto; flex: 1; }
    .topbar-title { display: none; }
    .layout { flex-direction: column; }
    .sidebar { width: 100%; flex-basis: auto; border-right: 0; border-bottom: 1px solid var(--border); }
    .cat-list { flex-direction: row; flex-wrap: wrap; }
    .fields, .form-grid, .wv-dependent { grid-template-columns: 1fr; }
    .fields dd { text-align: left; }
}
