:root {
    --ink: #253746;
    --muted: #607789;
    --page: #eaf3f9;
    --header: #d7e9f6;
    --surface: #ffffff;
    --surface-soft: #f5f9fc;
    --line: #c6d5e0;
    --line-soft: #d9e5ed;
    --accent: #0a6ed1;
    --accent-dark: #075aab;
    --accent-soft: #e3f0fb;
    --live: #159447;
    --danger: #a12d22;
    --shadow: 0 3px 10px rgba(37, 55, 70, .08);
    --shadow-hover: 0 8px 22px rgba(37, 55, 70, .13);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--page); font: 13px/1.45 Verdana, Geneva, sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.portal-tile, .module-card, .button, input, select { transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.app-shell { min-height: 100vh; }

.center-screen, .login-screen { min-height: 100vh; display: grid; place-content: center; padding: 20px; }
.login-screen { background: var(--page); }
.login-card { width: min(410px, calc(100vw - 28px)); display: grid; gap: 14px; padding: 28px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--surface); box-shadow: 0 14px 40px rgba(37,55,70,.12); text-align: left; }
.login-card h1 { margin: 0; font-size: 24px; font-weight: normal; }
.login-card p { margin: -4px 0 8px; color: var(--muted); }

.portal-mark { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 12px; border-radius: 8px; background: var(--accent); color: white; font-size: 12px; font-weight: bold; box-shadow: 0 4px 12px rgba(10,110,209,.2); }
.login-card .portal-mark { margin: 0 0 4px; }
.portal-mark.small { width: 34px; height: 34px; margin: 0; font-size: 9px; }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: bold; letter-spacing: .05em; text-transform: uppercase; }

label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; font-weight: bold; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; background: white; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,110,209,.1); }

.button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--accent); border-radius: 6px; padding: 8px 12px; background: var(--accent); color: white; font-size: 13px; font-weight: bold; text-decoration: none; }
.button:hover { border-color: var(--accent-dark); background: var(--accent-dark); box-shadow: 0 4px 10px rgba(10,110,209,.16); transform: translateY(-1px); }
.button.ghost { border-color: var(--line); background: white; color: var(--ink); }
.button.ghost:hover { border-color: var(--accent); background: var(--accent-soft); }
.button:disabled { cursor: default; opacity: .5; }
.button.full { width: 100%; padding: 10px 12px; }

.topbar { position: sticky; z-index: 10; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 54px; padding: 9px max(18px, calc((100vw - 1400px) / 2)); border-bottom: 1px solid rgba(185,207,223,.8); background: rgba(215,233,246,.92); box-shadow: 0 2px 12px rgba(37,55,70,.06); backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 9px; color: inherit; text-decoration: none; }
.brand strong, .brand small, .user-chip strong, .user-chip small, td small { display: block; }
.brand strong { font-size: 14px; }
.brand small, .user-chip small, td small { color: var(--muted); font-size: 11px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions select { min-width: 170px; padding: 7px 9px; background: rgba(255,255,255,.8); }
.user-chip { padding: 3px 10px; border-left: 1px solid #afc8da; }

.content { width: min(1400px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 50px; }
.workspace-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 2px 0 16px; }
.workspace-head h1 { margin: 3px 0 0; font-size: 27px; line-height: 1.15; font-weight: normal; }
.workspace-note { color: var(--muted); font-size: 13px; }

.portal-tiles, .module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 10px; margin-bottom: 22px; }
.portal-tile, .module-card { min-height: 126px; border: 1px solid var(--line-soft); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); text-align: left; }
.portal-tile { position: relative; display: flex; flex-direction: column; align-items: stretch; padding: 14px; overflow: hidden; }
.portal-tile span { font-size: 14px; }
.portal-tile strong { margin-top: auto; color: var(--muted); font-size: 22px; font-weight: normal; }
.portal-tile small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.portal-tile:before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: transparent; }
.portal-tile:hover { border-color: #a9c9df; box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.portal-tile.active { border-color: #a9c9df; background: var(--surface-soft); box-shadow: var(--shadow); }
.portal-tile.active:before { background: var(--accent); }

.module-card { position: relative; display: flex; flex-direction: column; align-items: start; min-height: 170px; padding: 15px; }
.module-card:hover { border-color: #a9c9df; box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.module-card h2 { margin: 12px 0 5px; font-size: 16px; }
.module-card p { flex: 1; margin: 0 0 14px; color: var(--muted); font-size: 12px; }
.module-icon { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #b7d6ee; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: bold; }
.module-card > .status-dot { position: absolute; top: 15px; right: 13px; }
.status-dot { color: var(--muted); font-size: 10px; font-weight: bold; text-transform: uppercase; }
.status-dot:before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 2px rgba(21,148,71,.14); }

.card, .stat-card { overflow: hidden; margin-bottom: 16px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
#companies, #users { scroll-margin-top: 70px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 15px; border-bottom: 1px solid var(--line-soft); background: var(--surface-soft); }
.card-head h2 { margin: 0; font-size: 16px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 11px 12px; border-bottom: 1px solid #e3ebf1; text-align: left; }
th { background: #eef5fa; color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:hover { background: #f2f8fc; }
.row-actions { display: flex; gap: 5px; }
.badge { display: inline-flex; padding: 3px 7px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-soft); color: var(--muted); font-size: 10px; font-weight: bold; text-transform: uppercase; }
.badge.active { border-color: #9dc6e6; color: var(--accent-dark); }
.badge.inactive { color: #777; }

.notice { margin-bottom: 14px; padding: 10px 12px; border: 1px solid #9fc6e4; border-radius: 7px; background: var(--accent-soft); color: var(--ink); font-size: 13px; }
.notice.error { border-color: #dfb2ac; background: #faecea; color: var(--danger); }
.empty { grid-column: 1 / -1; padding: 36px; color: var(--muted); text-align: center; }

.dialog-backdrop { position: fixed; z-index: 20; inset: 0; background: rgba(37,55,70,.38); }
.dialog { position: fixed; z-index: 30; top: 50%; left: 50%; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; transform: translate(-50%, -50%); padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 18px 50px rgba(37,55,70,.25); }
.dialog form { display: grid; gap: 12px; }
.dialog h2 { margin: 0 0 4px; font-size: 20px; font-weight: normal; }
.dialog-actions { display: flex; justify-content: end; gap: 6px; margin-top: 7px; }
.check { display: flex; align-items: center; grid-template-columns: auto 1fr; }
.check input { width: auto; }
.module-options { display: grid; gap: 5px; }
.module-option { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
.module-option input { width: auto; margin-top: 3px; }
.module-option strong, .module-option small { display: block; }
.module-option small { margin-top: 2px; color: var(--muted); font-weight: normal; }

@media (max-width: 720px) {
    .topbar { position: static; align-items: stretch; flex-direction: column; padding: 9px 12px; }
    .top-actions { flex-wrap: wrap; }
    .top-actions select { flex: 1; min-width: 140px; }
    .user-chip { display: none; }
    .content { width: min(100% - 20px, 1400px); padding-top: 16px; }
    .workspace-head { align-items: start; flex-direction: column; gap: 3px; }
    .workspace-head h1 { font-size: 23px; }
    .portal-tiles, .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .portal-tile { min-height: 112px; }
    .module-card { min-height: 160px; }
    .card-head { align-items: stretch; flex-direction: column; }
    .card-head .button { width: 100%; }
    .row-actions { flex-direction: column; }
}

@media (max-width: 430px) {
    .portal-tiles, .module-grid { grid-template-columns: 1fr 1fr; }
    .portal-tile, .module-card { min-width: 0; padding: 11px; }
    .portal-tile strong { font-size: 18px; }
    .module-card h2 { font-size: 14px; }
    .module-card p { font-size: 11px; }
    .dialog { padding: 17px; }
}

@media (prefers-reduced-motion: reduce) {
    .portal-tile, .module-card, .button, input, select { transition: none; }
    .portal-tile:hover, .module-card:hover, .button:hover { transform: none; }
}
