/* AGS - UI foundation
 * Purpose: one predictable spacing/layout/control system across desktop, tablet, and mobile.
 * New code should use clear names documented in docs/UI_STANDARDIZATION.md.
 * Legacy selectors remain supported so the UI can be migrated safely without changing application logic.
 */

:root {
  --ui-spacing-1: 4px;
  --ui-spacing-2: 8px;
  --ui-spacing-3: 12px;
  --ui-spacing-4: 16px;
  --ui-spacing-5: 20px;
  --ui-spacing-6: 24px;
  --ui-control-height: 44px;
  --ui-control-height-compact: 36px;
  --ui-control-radius: 10px;
  --ui-card-radius: 14px;
  --ui-border-color: var(--line, #e2e8ef);
  --ui-surface: var(--surface, #ffffff);
  --ui-primary: var(--primary, #0a968a);
  --ui-primary-dark: var(--primary-strong, #08766d);
  --ui-text: var(--ink, #1c2f3c);
  --ui-muted: var(--muted, #687986);
  --ui-danger: var(--danger, #c4453b);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
.workspace,
.content,
.card,
.form-card {
  min-width: 0;
}

img,
svg,
canvas,
video {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* ---------- Controls ---------- */

:where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  select,
  textarea
) {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  line-height: 1.35;
}

:where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]),
  select
) {
  min-height: var(--ui-control-height);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

:where(label, .field-group, .form-field) {
  min-width: 0;
  max-width: 100%;
}

.field-group,
.form-field {
  display: grid;
  gap: var(--ui-spacing-2);
}

.field-label {
  display: block;
  margin: 0;
  line-height: 1.35;
  color: var(--ui-text);
}

/* ---------- Buttons ---------- */

:where(
  button,
  .button,
  .button-primary,
  .button-secondary,
  .button-danger,
  .button-success
) {
  min-height: var(--ui-control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ui-spacing-2);
  line-height: 1.2;
  text-align: center;
  vertical-align: middle;
}

:where(.button-primary, button:not(.secondary):not(.ghost):not(.danger):not(.link-button):not(.icon-only)) {
  align-items: center;
  justify-content: center;
}

:where(.button-secondary, .secondary) {
  color: var(--ui-primary-dark);
  background: var(--primary-soft, #e8f7f5);
  border-color: #cdebe7;
}

:where(.button-danger, .danger, button.danger-action) {
  color: #fff;
  background: var(--ui-danger);
  border-color: var(--ui-danger);
}

:where(.button-success, button.success-action) {
  color: #fff;
  background: var(--success, #15785d);
  border-color: var(--success, #15785d);
}

.button-icon,
.icon-only {
  width: var(--ui-control-height);
  min-width: var(--ui-control-height);
  height: var(--ui-control-height);
  padding: 0;
  display: inline-grid;
  place-items: center;
}

/* ---------- Layout / columns ---------- */

.ui-grid,
.form-grid,
.form-grid-two-columns,
.form-grid-twelve-columns {
  display: grid;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  gap: var(--ui-spacing-4);
  align-items: start;
}

.form-grid-two-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid-twelve-columns {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.form-column-half {
  grid-column: span 6;
  min-width: 0;
}

.form-column-full {
  grid-column: 1 / -1;
  min-width: 0;
}

/* Existing AGS layout aliases. */
.grid,
.two,
.three,
.four,
.settings-grid,
.check-grid,
.report-summary,
.logo-config-grid,
.bulk-teacher-grid,
.attendance-card {
  min-width: 0;
  max-width: 100%;
  column-gap: var(--ui-spacing-4);
  row-gap: var(--ui-spacing-4);
}

:where(
  .grid,
  .two,
  .three,
  .four,
  .settings-grid,
  .check-grid,
  .report-summary,
  .logo-config-grid,
  .bulk-teacher-grid,
  .attendance-card
) > * {
  min-width: 0;
  max-width: 100%;
}

.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* ---------- Actions / toolbars ---------- */

:where(
  .actions,
  .form-actions,
  .toolbar,
  .toolbar-left,
  .toolbar-right,
  .dialog-actions
) {
  gap: var(--ui-spacing-2);
  align-items: center;
}

.form-actions {
  grid-column: 1 / -1;
}

:where(
  .actions,
  .form-actions,
  .toolbar-left,
  .toolbar-right,
  .dialog-actions
) > * {
  min-width: 0;
}

/* ---------- Cards ---------- */

:where(
  .card,
  .login-card,
  .role-access-card,
  .logo-config-card,
  .attendance-card,
  .app-dialog
) {
  min-width: 0;
  max-width: 100%;
}

:where(
  .card,
  .role-access-card,
  .logo-config-card,
  .attendance-card
) > :first-child {
  margin-top: 0;
}

:where(
  .card,
  .role-access-card,
  .logo-config-card,
  .attendance-card
) > :last-child {
  margin-bottom: 0;
}

/* ---------- Tables ---------- */

.tablewrap {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

table th,
table td {
  vertical-align: middle;
}

td.actions {
  align-items: center;
  gap: var(--ui-spacing-2);
}

/* ---------- Loading ---------- */

.loading-container,
.loader-card {
  display: grid;
  justify-items: center;
  align-items: center;
  gap: var(--ui-spacing-3);
  text-align: center;
}

.loading-spinner,
.loader-spinner {
  flex: 0 0 auto;
  align-self: center;
  vertical-align: middle;
  margin-block: 0;
}

.global-loader.show {
  place-items: center;
}

/* ---------- Text safety ---------- */

:where(
  .content,
  .card,
  .role-access-card,
  .attendance-card,
  .app-dialog
) {
  overflow-wrap: anywhere;
}

/* ---------- Responsive ---------- */

@media (max-width: 1000px) {
  .form-grid-two-columns,
  .two,
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .form-grid-two-columns,
  .two,
  .three,
  .four,
  .grid,
  .settings-grid,
  .logo-config-grid,
  .bulk-teacher-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-column-half,
  .form-column-full {
    grid-column: 1 / -1;
    width: 100%;
  }

  :where(
    .actions,
    .form-actions,
    .toolbar-left,
    .toolbar-right,
    .dialog-actions
  ) {
    width: 100%;
    flex-wrap: wrap;
  }

  :where(
    .actions,
    .form-actions,
    .toolbar-left,
    .toolbar-right
  ) > :where(button, .button, input, select) {
    max-width: 100%;
  }

  .search,
  .select-compact,
  .filter-value {
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  :where(.grid, .two, .three, .four, .settings-grid, .logo-config-grid, .bulk-teacher-grid) {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: var(--ui-spacing-3) !important;
  }

}

@media (max-width: 480px) {
  :where(
    .actions,
    .form-actions,
    .dialog-actions
  ) > :where(button, .button) {
    width: 100%;
  }
}


/* ==========================================================================
   AGS STABILIZATION 2026-10-02
   Precision contracts shared by desktop, tablet/iPad, Android and iPhone.
   This layer does not change business workflow or the established AGS look.
   ========================================================================== */

.button-primary,
.button-secondary,
.button-tertiary,
.button-danger {
  min-height: var(--ui-control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ui-spacing-2);
  padding: 9px 13px;
  border-radius: var(--ui-control-radius);
  line-height: 1.2;
  text-align: center;
  vertical-align: middle;
}

.button-primary {
  background: var(--ui-primary);
  color: #fff;
  border: 1px solid var(--ui-primary);
}

.button-secondary {
  background: var(--primary-soft, #e8f7f5);
  color: var(--ui-primary-dark);
  border: 1px solid #cdebe7;
}

.button-tertiary {
  background: #fff;
  color: var(--ui-primary-dark);
  border: 1px solid var(--ui-border-color);
}

.button-danger {
  background: var(--ui-danger);
  color: #fff;
  border: 1px solid var(--ui-danger);
}

:where(
  .content,
  .card,
  .form-card,
  .data-card,
  .settings-panel,
  .role-access-card,
  .attendance-card,
  .template-layout,
  .report-generator,
  .paper-preview
) {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

:where(
  .grid,
  .two,
  .three,
  .four,
  .settings-grid,
  .check-grid,
  .report-summary,
  .logo-config-grid,
  .bulk-teacher-grid
) {
  gap: var(--ui-spacing-4);
  align-items: start;
}

:where(
  .grid,
  .two,
  .three,
  .four,
  .settings-grid,
  .check-grid,
  .report-summary,
  .logo-config-grid,
  .bulk-teacher-grid
) > * {
  min-width: 0;
  max-width: 100%;
}

:where(label, fieldset) {
  min-width: 0;
}

label > :where(input, select, textarea, .password-field) {
  margin-top: 6px;
}

:where(.toolbar, .toolbar-left, .toolbar-right, .actions, .form-actions, .dialog-actions, .page-intro) {
  gap: var(--ui-spacing-2);
}

:where(.toolbar, .toolbar-left, .toolbar-right, .actions, .form-actions, .dialog-actions) > * {
  min-width: 0;
  max-width: 100%;
}

:where(button, .button, .button-primary, .button-secondary, .button-tertiary, .button-danger) {
  align-items: center;
  justify-content: center;
}

.tablewrap {
  width: 100%;
  max-width: 100%;
}

table:not(.responsive),
table.responsive {
  max-width: 100%;
}

table th,
table td {
  vertical-align: middle;
}

:where(.loader-card, .global-loader.show) {
  justify-items: center;
  align-items: center;
  text-align: center;
}

@media (min-width: 641px) and (max-width: 1100px) {
  .content {
    padding-inline: 18px;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  :where(.two, .settings-grid, .report-summary) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  :where(.three, .four) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-left,
  .toolbar-right {
    flex: 1 1 100%;
  }
}

@media (max-width: 820px) {
  .sidebar {
    width: min(330px, 88vw);
    max-width: min(330px, 88vw);
  }

  .content {
    width: 100%;
    padding-inline: 12px;
  }

  :where(.toolbar, .toolbar-left, .toolbar-right, .actions, .form-actions) {
    width: 100%;
    flex-wrap: wrap;
  }

  :where(.search, .select-compact, .filter-value) {
    min-width: 0;
    max-width: 100%;
  }

  .page-intro,
  .card-title,
  .detail-header {
    min-width: 0;
  }

  table.responsive td {
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  .content {
    padding-inline: 10px;
  }

  .card {
    padding: 13px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-actions > :where(button, .button) {
    width: 100%;
  }

  .dialog-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


/* ==========================================================================
   FINAL GO-LIVE RESPONSIVE CONTRACT — 2026-10-05
   Portrait phones/tablets are intentionally col-12 / one-column.
   Touch-device landscape is promoted to a 1280px desktop viewport by
   orientation-viewport.js, so the desktop layout is reused consistently.
   ========================================================================== */
@media (orientation: portrait) and (max-width: 1100px) {
  :where(
    .grid,
    .stats-grid,
    .two,
    .three,
    .four,
    .settings-grid,
    .report-summary,
    .import-types,
    .attendance-card,
    .fee-summary-grid,
    .logo-config-grid,
    .bulk-teacher-grid,
    .check-grid,
    .form-grid,
    .form-grid-two-columns,
    .form-grid-twelve-columns
  ) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  :where(
    .grid,
    .stats-grid,
    .two,
    .three,
    .four,
    .settings-grid,
    .report-summary,
    .import-types,
    .attendance-card,
    .fee-summary-grid,
    .logo-config-grid,
    .bulk-teacher-grid,
    .check-grid,
    .form-grid,
    .form-grid-two-columns,
    .form-grid-twelve-columns
  ) > * {
    grid-column: 1 / -1 !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  :where(.actions, .form-actions, .dialog-actions, .toolbar-left, .toolbar-right) {
    width: 100% !important;
    max-width: 100% !important;
  }

  .form-actions,
  .dialog-actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .form-actions > *,
  .dialog-actions > * {
    width: 100% !important;
    min-width: 0 !important;
  }

  .tablewrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  table.responsive {
    display: table !important;
    width: 100% !important;
    min-width: 720px !important;
  }
  table.responsive thead { display: table-header-group !important; }
  table.responsive tbody { display: table-row-group !important; }
  table.responsive tr { display: table-row !important; border: 0 !important; padding: 0 !important; }
  table.responsive th,
  table.responsive td {
    display: table-cell !important;
    width: auto !important;
    border-bottom: 1px solid #edf1f5 !important;
    padding: 10px !important;
  }
  table.responsive td::before { display: none !important; content: none !important; }
}

/* DECISION-AGS-001: Google Drive reconnect */
.drive-reconnect-actions{display:flex;flex-wrap:wrap;gap:12px;margin:14px 0}
.drive-reconnect-actions button{min-height:44px;max-width:100%;white-space:normal;overflow-wrap:anywhere}
@media(max-width:680px){.drive-reconnect-actions,.drive-reconnect-actions button{width:100%}}

/* AGS brand surfaces: clear hierarchy without decorative fills on controls. */
:root {
  --canvas:#f3f7f7;
  --surface:#ffffff;
  --ink:#183941;
  --muted:#627782;
  --line:#dae6e7;
  --primary-soft:#e8f6f2;
  --shadow:0 12px 30px rgba(24,66,68,.055);
}
body {background:var(--canvas);color:var(--ink)}
.login-page {background:#f5f9f8}
.login-brand {background:#e7f5f1;border-right:1px solid #cfebe4}
.login-brand::before,.login-brand::after {display:none}
.login-brand h1 {color:#16463f;letter-spacing:-.045em}
.login-brand p {color:#496b69;line-height:1.6}
.login-card {border:1px solid #dae8e5;border-top:4px solid var(--primary);border-radius:20px;box-shadow:0 24px 55px rgba(20,75,69,.13);padding:clamp(24px,3vw,38px)}
.login-card h2 {color:#1a4440}
.sidebar {background:#fcfefe;border-right:1px solid #d5e6e4}
.brand-row {border-color:#d5e6e4}
.brand-row strong {color:#1a4942}
.nav-group {color:#6b8585;letter-spacing:.11em}
.nav-item {color:#496d6a;font-weight:560;border-radius:10px;transition:background-color .15s,color .15s}
.nav-item:hover {background:#eff8f5;color:#164e46;transform:none}
.nav-item.active {background:#dff3ed;color:#095f55;box-shadow:inset 3px 0 #0a968a}
.topbar {background:#fff;border-bottom:1px solid #d9e8e5;backdrop-filter:none}
.page-heading h1 {font-weight:740;letter-spacing:-.025em;color:#153e39}
.content {width:100%;max-width:none;padding:clamp(18px,2.3vw,36px)}
.page-intro {align-items:center;gap:16px;margin-bottom:22px}
.page-intro h2 {font-size:clamp(1.32rem,1.6vw,1.7rem);font-weight:730;letter-spacing:-.032em;color:#193f3a}
.page-intro p {line-height:1.55}
.card {border:1px solid #dde9e7;border-radius:15px;box-shadow:0 4px 18px rgba(26,61,61,.035);padding:clamp(16px,1.7vw,24px)}
.card.soft {background:#f7fbf9}
.card-title {margin-bottom:18px}
.card-title h2 {font-size:1.15rem;font-weight:720;letter-spacing:-.016em}
.stat {align-items:flex-start;gap:14px}
.stat-icon {background:#e3f4ee;color:#146f5d;border-radius:12px}
.stat b {color:#153d39;font-size:1.55rem;letter-spacing:-.025em}
.accent-card {background:#eaf6f1;border:1px solid #cfe8de;box-shadow:none}
.accent-card h2 {color:#194d43}
.data-card {padding:clamp(12px,1.3vw,20px)}
.toolbar {margin-bottom:14px;padding-bottom:13px;border-bottom:1px solid #e7eeee}
.toolbar-right {gap:9px}
.result-count {font-weight:550;color:#617b79}
.search input {background:#fafdfc;border:1px solid #cbdedb;border-radius:10px}
.search input:focus {background:#fff}
.tablewrap {border:1px solid #e1eae9;border-radius:12px;overflow-x:auto}
table.responsive {border-collapse:separate;border-spacing:0}
table.responsive th {background:#f0f7f5;border-top:0;color:#526c69;font-size:.7rem;font-weight:750;padding:13px 12px;letter-spacing:.045em}
table.responsive td {border-bottom:1px solid #edf2f1;padding:13px 12px;line-height:1.45}
table.responsive tbody tr:nth-child(2n) td {background:#fcfefd}
table.responsive tbody tr:hover td {background:#eff8f5}
td.actions {white-space:normal}
td.actions button {min-height:36px;white-space:nowrap}
.table-action {background:#fff;color:#146c60;border:1px solid #cae3df;border-radius:8px;padding:7px 10px;box-shadow:none}
.table-action:hover {background:#e8f6f2;color:#0b5d52;transform:none}
.badge {border-radius:7px;font-weight:700}
.badge.success {background:#ddf3ea;color:#17614d}
.badge.warning {background:#fff1d7;color:#825719}
.form-card {width:100%;max-width:none}
.form-stack {display:grid;grid-template-columns:minmax(0,1fr);gap:10px}
.form-stack>label {min-width:0;width:100%;margin:0}
.form-stack input,.form-stack select,.form-stack textarea {width:100%}
label {font-weight:650;color:#36544f}
input,select,textarea {border-color:#cbdad8;border-radius:9px}
input:focus,select:focus,textarea:focus {border-color:#0a968a;box-shadow:0 0 0 3px rgba(10,150,138,.11)}
.form-actions {padding-top:10px;gap:10px}
button,.button {border-radius:9px}
button:not(:disabled):hover {transform:none}
button:focus-visible,.button:focus-visible,a:focus-visible {outline:3px solid #0a968a;outline-offset:2px}
button.secondary {background:#e8f5f1;color:#17685c;border:1px solid #c3ded7}
button.secondary:hover {background:#d7eee6}
button.ghost {background:#fff;color:#415a59;border:1px solid #d1dfdc}
button.ghost:hover {background:#f4f8f7}
button.danger,button.danger-action {background:#fff0ee;border:1px solid #e8b7af;color:#9b382d}
button.danger:hover,button.danger-action:hover {background:#ffe2dd}
button.success-action {background:#17785e;border-color:#17785e;color:#fff}
.session-wizard {border:1px solid #cfe9e3;border-left:4px solid #0a968a;background:#fcfffe}
.session-editor .status-row {margin:8px 0 12px}
.session-editor .section-divider {margin-top:24px}
.session-editor .attendance-card {border-color:#d7e7e3;background:#fff;border-radius:12px;padding:14px}
.attendance-name strong {color:#17453d}
#legacy-correction-form {border-left:4px solid #17785e}
.settings-grid .setting-tile {border:1px solid #dce9e6;background:#fff;border-radius:12px;box-shadow:0 4px 12px rgba(25,76,64,.035)}
.settings-grid .setting-tile:hover {border-color:#b7d9ce;background:#f6fcf9}
.password-toggle,.password-toggle.icon-only {background:transparent!important;border:0!important;box-shadow:none!important;color:#56716b!important}
.password-toggle:hover,.password-toggle:active,.password-toggle:focus-visible {background:transparent!important;border:0!important;box-shadow:none!important;color:#08766d!important}
.password-toggle svg {fill:none;stroke:currentColor}
@media (max-width:1050px) {
  .content {padding:20px}
  .page-intro {align-items:flex-start}
  .stats-grid {grid-template-columns:repeat(3,minmax(0,1fr))}
}
@media (max-width:820px) {
  .page-intro {flex-direction:column;align-items:stretch}
  .page-intro>.actions {width:100%;justify-content:flex-start}
  .stats-grid {grid-template-columns:repeat(2,minmax(0,1fr))}
  .toolbar-left,.toolbar-right {width:100%}
  .search {min-width:0;flex:1}
}
@media (max-width:640px) {
  .content {padding:15px 12px 100px}
  .login-page {background:#eef8f5}
  .login-brand {background:transparent;border-right:0}
  .login-card {box-shadow:0 14px 34px rgba(20,75,69,.09)}
  .page-intro h2 {font-size:1.38rem}
  .stats-grid {grid-template-columns:repeat(2,minmax(0,1fr))}
  .stat {padding:13px}
  .stat b {font-size:1.32rem}
  .card {padding:15px}
  .form-actions {align-items:stretch}
  .tablewrap {margin-inline:0}
  .session-wizard .form-stack {grid-template-columns:minmax(0,1fr)}
}
@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after {scroll-behavior:auto!important;animation-duration:.01ms!important;transition-duration:.01ms!important}
}
