:root {
  --bg: #eef2f5;
  --ink: #18202a;
  --muted: #687484;
  --panel: #fff;
  --line: #d7e0e7;
  --dark: #152332;
  --blue: #1f5e8c;
  --green: #4d7c43;
  --amber: #9a6700;
  --red: #b83232;
  --shadow: 0 10px 28px rgba(24, 32, 42, 0.08);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: #dfe7ed; }
.login-card { width: min(420px, 100%); padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand span { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; background: #f2b705; color: #17202a; font-weight: 800; }
.brand h1, .brand p, .topbar h2, .topbar p, .dialog-header h2, .dialog-header p { margin: 0; }
.brand h1 { font-size: 18px; }
.brand p, .topbar p, .dialog-header p, .muted { color: var(--muted); font-size: 13px; }
.login-brand { margin-bottom: 22px; }
.login-form, .app-form { display: grid; gap: 12px; }
label { display: grid; gap: 5px; color: #3b4652; font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); padding: 0 11px; }
textarea { padding-top: 9px; resize: vertical; }
.login-form button, .dialog-actions button, .admin-only { min-height: 40px; border: 0; border-radius: 8px; padding: 0 14px; background: var(--blue); color: #fff; font-weight: 700; }
.error { min-height: 18px; margin: 0; color: var(--red); font-size: 13px; }
.success { color: var(--green); }
.primary-link { display: inline-grid; place-items: center; min-height: 40px; border-radius: 8px; background: var(--blue); color: #fff; text-decoration: none; font-weight: 700; }

.portal-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { display: flex; flex-direction: column; gap: 24px; padding: 22px 16px; background: var(--dark); color: #fff; }
nav { display: grid; gap: 8px; }
.nav, .admin-button, .logout-button { min-height: 40px; border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 8px; background: transparent; color: #fff; text-align: left; padding: 0 12px; }
.nav { display: flex; align-items: center; gap: 9px; }
.nav-mark { width: 8px; height: 8px; border-radius: 50%; background: #7f93a5; }
.nav.active { background: #23384d; border-color: #49677f; }
.nav.active .nav-mark { background: #f2b705; }
.sidebar-bottom { display: grid; gap: 8px; margin-top: auto; }
.admin-button { background: #294761; }
.logout-button { text-align: center; }
.sidebar-bottom div { display: grid; gap: 3px; padding: 8px 2px 0; }
.sidebar-bottom span { color: #9caab6; font-size: 12px; }

.content { min-width: 0; padding: 26px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar h2 { font-size: 25px; }
.top-actions { display: flex; gap: 9px; align-items: center; }
.top-actions input { width: min(340px, 42vw); }
.summary { display: grid; grid-template-columns: repeat(3, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.metric { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.metric span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.metric strong { font-size: 22px; }
.apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.app-tile { overflow: hidden; border: 1px solid var(--line); border-top: 5px solid var(--accent); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.app-main { width: 100%; min-height: 154px; display: grid; grid-template-columns: 62px minmax(0, 1fr) 24px; gap: 14px; align-items: center; border: 0; background: #fff; color: inherit; padding: 18px; text-align: left; }
.app-main:not(.disabled):hover { background: #f7fafc; }
.app-main.disabled { cursor: default; opacity: 0.72; }
.app-symbol { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 800; }
.app-copy { display: grid; gap: 6px; min-width: 0; }
.app-copy strong { font-size: 19px; }
.app-copy > span:last-child { color: var(--muted); font-size: 13px; line-height: 1.4; }
.app-meta { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.open-arrow { color: var(--accent); font-size: 32px; line-height: 1; }
.app-tile footer { display: flex; justify-content: space-between; align-items: center; min-height: 48px; border-top: 1px solid var(--line); padding: 8px 12px; background: #f8fafb; }
.status { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 2px 9px; background: #eef1f4; color: #344252; font-size: 12px; font-weight: 700; }
.status.active { background: #e4f2df; color: var(--green); }
.status.pending { background: #fff2d4; color: var(--amber); }
.status.hidden-state { background: #f0e7e7; color: var(--red); }
.edit-button { min-height: 30px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: #263241; padding: 0 10px; }
.empty { color: var(--muted); }

dialog { width: min(720px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 8px; padding: 0; box-shadow: 0 24px 70px rgba(18, 29, 40, 0.24); }
dialog::backdrop { background: rgba(15, 25, 35, 0.58); }
.app-form { padding: 20px; }
.dialog-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 9px; min-height: 40px; }
.check input { width: 18px; min-height: 18px; }
.form-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.dialog-actions { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; }
.dialog-actions .secondary { background: #e9eef2; color: #263241; }
.dialog-actions .danger { background: var(--red); }

.users-dialog { width: min(1000px, calc(100% - 28px)); }
.users-panel { padding: 20px; }
.users-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; margin-top: 16px; }
.users-layout aside { min-width: 0; border-right: 1px solid var(--line); padding-right: 16px; }
.new-user-button { width: 100%; min-height: 40px; border: 0; border-radius: 8px; background: var(--blue); color: #fff; font-weight: 700; }
.users-list { display: grid; gap: 7px; margin-top: 10px; max-height: 520px; overflow: auto; }
.user-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) 10px; gap: 9px; align-items: center; width: 100%; min-height: 58px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); padding: 8px; text-align: left; }
.user-row.selected { border-color: #6d96b4; background: #eef6fb; }
.user-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: #23384d; color: #fff; font-size: 12px; font-weight: 800; }
.user-row strong, .user-row small { display: block; }
.user-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.user-state { width: 9px; height: 9px; border-radius: 50%; background: #b8c1c9; }
.user-state.on { background: var(--green); }
.user-form { display: grid; align-content: start; gap: 14px; }
#permissionsSection { border-top: 1px solid var(--line); padding-top: 14px; }
#permissionsSection h3, #permissionsSection p { margin: 0; }
#permissionsSection h3 { font-size: 15px; }
#permissionsSection p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.permissions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 9px; margin-top: 11px; }
.permission-card { display: grid; grid-template-columns: 18px 38px minmax(0, 1fr); gap: 9px; align-items: center; min-height: 60px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; background: #fff; padding: 8px; cursor: pointer; }
.permission-card input { width: 17px; min-height: 17px; }
.permission-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; }
.permission-card strong, .permission-card small { display: block; }
.permission-card small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.disabled-section { opacity: 0.62; }

@media (max-width: 950px) {
  .portal-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 3; flex-direction: row; align-items: center; overflow: auto; }
  nav { display: flex; }
  .sidebar-bottom { display: flex; align-items: center; margin-left: auto; margin-top: 0; }
  .sidebar-bottom div { display: none; }
}

@media (max-width: 680px) {
  .content { padding: 14px; }
  .topbar, .top-actions { flex-direction: column; width: 100%; }
  .top-actions input, .top-actions button { width: 100%; }
  .summary, .form-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .app-main { grid-template-columns: 54px minmax(0, 1fr); }
  .open-arrow { display: none; }
  .dialog-actions { grid-template-columns: 1fr; }
  .users-layout { grid-template-columns: 1fr; }
  .users-layout aside { border-right: 0; border-bottom: 1px solid var(--line); padding-right: 0; padding-bottom: 14px; }
}
