/* Tokens Material 3 + ajustes de layout do RGR. */
:root {
  --md-sys-color-primary: #4f5b92;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #dde1f9;
  --md-sys-color-on-primary-container: #050f42;
  --md-sys-color-secondary: #5a5d72;
  --md-sys-color-surface: #fbf8ff;
  --md-sys-color-surface-container: #efedf5;
  --md-sys-color-surface-container-high: #e9e7ef;
  --md-sys-color-on-surface: #1b1b21;
  --md-sys-color-on-surface-variant: #45464f;
  --md-sys-color-outline: #767680;
  --md-sys-color-outline-variant: #c6c5d0;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  --rgr-radius: 12px;
  --rgr-gap: 16px;
  --rgr-max-width: 1120px;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--md-sys-color-primary); }

.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__inner {
  max-width: var(--rgr-max-width);
  margin: 0 auto;
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: .3px;
}

.topbar__nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.topbar__nav a,
.topbar__logout button {
  color: inherit;
  text-decoration: none;
  font: inherit;
  font-weight: 500;
  background: none;
  border: 0;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.topbar__nav a:hover,
.topbar__logout button:hover { background: rgba(255, 255, 255, .14); }

.topbar__logout { margin: 0; }

.topbar__user {
  margin-left: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  font-size: 13px;
}

/* -------------------------------------------------------------------- page */

.page {
  max-width: var(--rgr-max-width);
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.page--narrow { max-width: 460px; }

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-head h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 500;
}

.page-head__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--rgr-radius);
  padding: 20px;
  margin-bottom: 24px;
}

.card__title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 500;
}

.card__subtitle {
  margin: 0 0 16px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
}

.muted { color: var(--md-sys-color-on-surface-variant); }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
}

/* ------------------------------------------------------------------ forms */

.field { margin-bottom: 16px; display: block; }

.field md-outlined-text-field { width: 100%; }

.form-row {
  display: flex;
  gap: var(--rgr-gap);
  flex-wrap: wrap;
}

.form-row > .field { flex: 1 1 220px; }

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.form-actions .spacer { flex: 1; }

.alert {
  border-radius: var(--rgr-radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.alert--info {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.hint {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
}

/* ----------------------------------------------------------------- tabelas */

.table-wrap {
  overflow-x: auto;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--rgr-radius);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data th,
table.data td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}

table.data th {
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12px;
  letter-spacing: .5px;
  text-transform: uppercase;
}

table.data tbody tr:last-child td { border-bottom: 0; }

table.data tbody tr:hover { background: var(--md-sys-color-surface-container-high); }

table.data td.col-name { white-space: normal; }

td.actions, th.actions { text-align: right; width: 1%; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.chip--off {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border-color: transparent;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters a {
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
}

.filters a.is-active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: transparent;
}

/* --------------------------------------------------------------- arquivos */

.files__toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.files__toolbar .spacer { flex: 1; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 14px;
}

.breadcrumb button {
  background: none;
  border: 0;
  font: inherit;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.breadcrumb button:hover { background: var(--md-sys-color-surface-container-high); }

.breadcrumb .sep { color: var(--md-sys-color-outline); }

.files__list { position: relative; min-height: 200px; }

.files__list.is-dragover::after {
  content: "Solte para enviar os arquivos";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--md-sys-color-primary);
  border-radius: var(--rgr-radius);
  background: rgba(79, 91, 146, .08);
  color: var(--md-sys-color-primary);
  font-weight: 500;
  pointer-events: none;
  z-index: 2;
}

tr.file-row { cursor: pointer; }

tr.file-row.is-drop-target td { background: var(--md-sys-color-primary-container); }

tr.file-row td.col-name {
  display: flex;
  align-items: center;
  gap: 10px;
}

tr.file-row .material-symbols-outlined { color: var(--md-sys-color-on-surface-variant); }

.icon-btn {
  background: none;
  border: 0;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 0;
}

.icon-btn:hover { background: var(--md-sys-color-surface-container-high); }

.progress {
  height: 4px;
  border-radius: 999px;
  background: var(--md-sys-color-surface-container-high);
  overflow: hidden;
  margin-bottom: 12px;
}

.progress__bar {
  height: 100%;
  width: 0;
  background: var(--md-sys-color-primary);
  transition: width .15s linear;
}

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  flex-direction: column;
  background: var(--md-sys-color-surface);
}

.modal.is-open { display: flex; }

.modal__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container);
  flex-wrap: wrap;
}

.modal__title {
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50vw;
}

.modal__title small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.modal__actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.modal__body {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #fff;
}

.modal__body .cm-editor { height: 100%; }

.modal__body .cm-scroller { font-family: "Roboto Mono", ui-monospace, "Courier New", monospace; }

.modal__body img.preview {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: 24px auto;
  object-fit: contain;
}

.modal__fallback {
  width: 100%;
  height: 100%;
  border: 0;
  padding: 16px;
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 13px;
  resize: none;
  outline: none;
}

.modal__status {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  padding: 6px 16px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container);
}

.modal__status.is-dirty { color: var(--md-sys-color-error); }

/* ------------------------------------------------------------- snackbars */

.snackbars {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.snackbar {
  background: #303038;
  color: #f2f0f7;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
  font-size: 14px;
  max-width: 90vw;
  animation: snack-in .2s ease-out;
}

.snackbar--error { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }

@keyframes snack-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ dialog */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .38);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}

.dialog-backdrop.is-open { display: flex; }

.dialog {
  background: var(--md-sys-color-surface-container);
  border-radius: 28px;
  padding: 24px;
  width: min(420px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
}

.dialog h2 { margin: 0 0 8px; font-size: 20px; font-weight: 400; }

.dialog p { margin: 0 0 16px; color: var(--md-sys-color-on-surface-variant); }

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.dialog input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  color: inherit;
}

.dialog .tree-pick {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  max-height: 240px;
  overflow: auto;
  background: var(--md-sys-color-surface);
}

.dialog .tree-pick button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  font: inherit;
  padding: 10px 12px;
  cursor: pointer;
  color: inherit;
}

.dialog .tree-pick button:hover { background: var(--md-sys-color-surface-container-high); }

.dialog .tree-pick button.is-selected { background: var(--md-sys-color-primary-container); }

@media (max-width: 640px) {
  .topbar__user { display: none; }
  .modal__title { max-width: 40vw; }
  table.data th.hide-sm, table.data td.hide-sm { display: none; }
}

/* ------------------------------- fallback quando o Material Web não carrega */

.md-fallback md-filled-button,
.md-fallback md-filled-tonal-button,
.md-fallback md-text-button,
.md-fallback md-outlined-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}

.md-fallback md-filled-button {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.md-fallback md-filled-tonal-button {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.md-fallback md-text-button,
.md-fallback md-outlined-button {
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.fallback-field { display: block; margin-bottom: 4px; }

.fallback-field span {
  display: block;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 4px;
}

.fallback-field input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  color: inherit;
}

/* --------------------------------------------------- busca na lista de arquivos */

.files__search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  min-width: 220px;
}

.files__search .material-symbols-outlined { color: var(--md-sys-color-on-surface-variant); }

.files__search input {
  border: 0;
  outline: none;
  background: none;
  font: inherit;
  color: inherit;
  padding: 6px 0;
  flex: 1;
  min-width: 0;
}

.files__search input::-webkit-search-cancel-button { display: none; }

.files__searching { color: var(--md-sys-color-primary); }

tr.file-row td.col-name .file-parent {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12px;
}
