:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --ink: #1b1f27;
    --muted: #667085;
    --line: #e3e6eb;
    --accent: #1f4fd1;
    --accent-ink: #ffffff;
    --accent-soft: #e8eefc;
    --danger: #c62f2f;
    --success-bg: #e7f6ec;
    --success-ink: #19663a;
    --error-bg: #fdecec;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 1.5rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #6b8cff); }
.nav { display: flex; align-items: center; gap: 1.25rem; }
.nav a:not(.btn) { color: var(--muted); font-weight: 500; }
.nav a.active { color: var(--ink); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: #c9ced6; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #1a43b3; border-color: #1a43b3; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: .85rem; cursor: pointer; margin-left: .5rem; }

/* Notices */
.notice { margin: 1.25rem 0 0; padding: .7rem 1rem; border-radius: 8px; background: var(--success-bg); color: var(--success-ink); }
.notice-error { background: var(--error-bg); color: var(--danger); }

/* Toolbar */
.toolbar { margin: 1.5rem 0; display: grid; gap: 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
    padding: .35rem .85rem; border-radius: 999px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink); font-weight: 500; font-size: .9rem;
}
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.search { display: flex; gap: .5rem; flex-wrap: wrap; }
.search input[type=search] { flex: 1 1 240px; }

input[type=text], input[type=search], select, textarea {
    font: inherit; color: inherit; padding: .5rem .7rem; border: 1px solid var(--line);
    border-radius: 8px; background: var(--surface); width: 100%; max-width: 100%;
}
.search select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* Library */
.category { margin-bottom: 2rem; }
.category h2 { display: flex; align-items: center; gap: .5rem; }
.count { font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--line); border-radius: 999px; padding: 0 .5rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }

.card {
    display: flex; flex-direction: column; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.thumb {
    aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center;
    background: repeating-conic-gradient(#f0f2f5 0 25%, #fafbfc 0 50%) 0 0 / 16px 16px;
    border-bottom: 1px solid var(--line);
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.ext { font-weight: 700; letter-spacing: .05em; padding: .5rem .8rem; border-radius: 8px; background: #475467; color: #fff; }
.ext-pptx, .ext-potx, .ext-ppt { background: #c4502b; }
.ext-docx, .ext-dotx, .ext-doc { background: #2b579a; }
.ext-pdf { background: #b42318; }
.ext-ai, .ext-eps { background: #d97706; }

.card-body { padding: .9rem 1rem .5rem; flex: 1; }
.card-body h3 { font-size: 1rem; margin: 0 0 .3rem; }
.desc { margin: 0 0 .5rem; color: var(--muted); font-size: .9rem; }
.tags { list-style: none; padding: 0; margin: 0 0 .5rem; display: flex; flex-wrap: wrap; gap: .3rem; }
.tags li { font-size: .75rem; font-weight: 600; padding: .1rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.meta { margin: 0; color: var(--muted); font-size: .8rem; word-break: break-all; }
.card-actions { display: flex; gap: .5rem; padding: .5rem 1rem 1rem; }
.card-actions .btn-primary { flex: 1; }

.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Forms */
.form-page { max-width: 680px; margin: 0 auto 3rem; }
.back { display: inline-block; margin-top: 1.5rem; font-size: .9rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.field { margin: 0 0 1.1rem; border: 0; padding: 0; min-width: 0; }
.field label, .field legend { display: block; font-weight: 600; margin-bottom: .35rem; padding: 0; }
.optional { font-weight: 400; color: var(--muted); font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .35rem 0 0; }
.error { color: var(--danger); font-size: .85rem; margin: .35rem 0 0; }
.has-error input, .has-error select, .has-error .tag-picker { border-color: var(--danger); }
.form-actions { display: flex; gap: .5rem; }
.thumb-current { max-width: 280px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; overflow: hidden; }
.field label.checkbox { display: flex; align-items: center; gap: .4rem; font-weight: 400; font-size: .9rem; margin-top: .5rem; }

.tag-picker { display: flex; flex-wrap: wrap; gap: .5rem; border: 1px solid transparent; border-radius: 8px; }
.tag-option { position: relative; margin: 0 !important; }
.tag-option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.tag-option span {
    display: inline-block; padding: .4rem .9rem; border-radius: 999px; border: 1px solid var(--line);
    font-weight: 500; font-size: .9rem; background: var(--surface); cursor: pointer; user-select: none;
}
.tag-option input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tag-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.danger-zone {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    border: 1px solid #f3c4c4; border-radius: var(--radius); padding: 1rem 1.25rem; background: #fffafa;
}

/* Header user menu */
.user-menu { display: flex; align-items: center; gap: .75rem; margin: 0; padding-left: 1rem; border-left: 1px solid var(--line); }
.user-name { font-weight: 500; font-size: .9rem; display: flex; align-items: center; gap: .4rem; }
.user-menu .link { margin: 0; font-size: .9rem; }

/* Login */
.login { display: flex; justify-content: center; padding: 4rem 0; }
.login-panel { width: 100%; max-width: 420px; text-align: center; padding: 2rem 1.75rem; }
.login-panel h1 { margin: .75rem 0 .25rem; font-size: 1.4rem; }
.login-panel .notice { text-align: left; margin: 1rem 0 0; }
.brand-mark-lg { display: inline-block; width: 40px; height: 40px; border-radius: 10px; }
.login-buttons { display: grid; gap: .6rem; margin-top: 1.5rem; }
.btn-provider { gap: .6rem; padding: .7rem 1rem; font-weight: 600; }
.ms-logo { width: 18px; height: 18px; }
.forbidden { margin-top: 2rem; }
.forbidden h1 { margin-top: 0; }

/* Companies */
.add-company { margin-top: 1rem; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 0 1rem; align-items: flex-end; }
.inline-fields .grow { flex: 1 1 260px; }
.inline-fields .order { flex: 0 0 130px; }
input[type=number] { font: inherit; color: inherit; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: 100%; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .55rem; border-radius: 999px; }
.badge-active { background: var(--success-bg); color: var(--success-ink); }
.badge-archived { background: var(--line); color: var(--muted); }
tr.is-archived td { color: var(--muted); }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: .85rem; background: var(--bg); padding: .1rem .35rem; border-radius: 4px; }

/* Stats */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); }
.stat-value { display: block; font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
