/*
 * Application-wide styles. Propshaft serves every file in app/assets/stylesheets;
 * no build step. Inline style attributes are blocked by the CSP, so use classes.
 */

:root {
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-text: #1f2328;
  --color-muted: #656d76;
  --color-border: #d8dee4;
  --color-primary: #c96442;
  --color-primary-hover: #b05535;
  --color-alert-bg: #fff1f0;
  --color-alert-text: #a40e26;
  --color-notice-bg: #eefbf1;
  --color-notice-text: #116329;
  --radius: 8px;
  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, system-ui, sans-serif;
}

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

/* The hidden attribute must win over component display rules (e.g. .button { display: inline-flex }). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
}

h1, h2, h3 { line-height: 1.4; margin: 0 0 0.75em; }
h2 { font-size: 1.3rem; }
a { color: var(--color-primary); }

.muted { color: var(--color-muted); }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.app-header__brand { font-weight: bold; color: var(--color-text); text-decoration: none; }
.app-header__nav { display: flex; align-items: center; gap: 1rem; }
.app-header__nav form { margin: 0; }
.app-header__user { color: var(--color-muted); }
.app-header__usage { font-size: 0.85rem; color: var(--color-muted); white-space: nowrap; }
/* Company logo, right of the logout button (the image is 2x for sharp high-DPI screens). */
.app-header__logo { display: block; width: auto; height: 36px; margin-left: 0.5rem; }
@media (max-width: 760px) {
  .app-header__logo { display: none; }
}

.app-main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem; }
.app-main--wide { max-width: 1440px; }

/* ---------- Auth screens ---------- */
.auth-body { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; padding: 8vh 1rem 2rem; }
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.auth-card__brand { font-size: 1.1rem; color: var(--color-muted); text-align: center; }
.auth-card__footer { margin-top: 1.25rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.auth-card__footer form { margin: 0; }

/* ---------- Panels / page header ---------- */
.panel {
  padding: 1.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-header h2 { margin: 0; }

/* ---------- Flash ---------- */
.flash { padding: 0.6rem 0.9rem; margin-bottom: 1rem; border-radius: var(--radius); }
.flash--alert { background: var(--color-alert-bg); color: var(--color-alert-text); }
.flash--notice { background: var(--color-notice-bg); color: var(--color-notice-text); }
.form-errors { margin: 0; padding-left: 1.2rem; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form__field { display: flex; flex-direction: column; gap: 0.25rem; }
.form__field label { font-weight: bold; font-size: 0.9rem; }
.form__actions { display: flex; gap: 0.5rem; }
.form__row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.form__fieldset { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; padding: 0.75rem 1rem; border: 1px solid var(--color-border); border-radius: var(--radius); }
.form__fieldset legend { padding: 0 0.3rem; font-weight: bold; font-size: 0.9rem; }
.form__checks { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.form__check { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: normal; }
.form__check input { width: auto; }
.form__indent { margin-left: 1.6rem; padding: 0.4rem 0.6rem; background: var(--color-bg); border-radius: 6px; }
.category-scope--restricted { font-weight: bold; color: var(--color-primary); }
.category-scope--nobody { color: var(--color-alert-text); }

/* ---------- Status badges ---------- */
.status { display: inline-block; padding: 0.05rem 0.5rem; font-size: 0.8rem; border-radius: 999px; }
.status--active { color: var(--color-notice-text); background: var(--color-notice-bg); }
.status--invited { color: #7a5200; background: #fff8e5; }
.status--inactive { color: var(--color-muted); background: var(--color-bg); }
.status--uninvited { color: #1f4f8a; background: #e8f0fb; }
.status--error { color: var(--color-alert-text); background: var(--color-alert-bg); }
.steps { margin: 0 0 1rem; padding-left: 1.4rem; line-height: 1.8; }
.callout { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 0.6rem 0.9rem; margin-bottom: 1rem; color: #1f4f8a; background: #e8f0fb; border-radius: var(--radius); }
.callout form { margin: 0; }
.table tr.is-inactive td { color: var(--color-muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: inherit;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-primary); outline-offset: 0; }
.input--code { font-size: 1.5rem; letter-spacing: 0.4em; text-align: center; }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button--primary { color: #fff; background: var(--color-primary); }
.button--primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.button--subtle { color: var(--color-text); background: var(--color-surface); border-color: var(--color-border); }
.button--subtle:hover { background: var(--color-bg); }
.button--link { color: var(--color-primary); background: none; padding: 0; text-decoration: underline; }
.button--block { width: 100%; padding: 0.6rem; }

/* ---------- Dialogs (confirmations, renaming) ---------- */
.dialog {
  width: min(420px, calc(100vw - 2rem));
  padding: 0; /* the body has the padding, so a click on the dialog itself is a backdrop click */
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog__body { display: flex; flex-direction: column; gap: 0.9rem; margin: 0; padding: 1.25rem; }
.dialog__title { margin: 0; font-size: 1.05rem; }
.dialog__message { margin: 0; line-height: 1.6; white-space: pre-line; overflow-wrap: anywhere; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.table th, .table td { padding: 0.55rem 0.75rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.table th { font-size: 0.85rem; color: var(--color-muted); background: var(--color-bg); }
.table--narrow { width: auto; min-width: 480px; }
/* Dense admin lists: fit ~10 columns in a 1,200px window without horizontal scrolling. */
.table--compact { font-size: 0.85rem; line-height: 1.5; }
.table--compact th, .table--compact td { padding: 0.45rem 0.5rem; }
.table--compact th { font-size: 0.8rem; }
.table--compact td { overflow-wrap: anywhere; }
.table--compact .button--small { padding: 0.2rem 0.45rem; font-size: 0.78rem; }
.table-scroll { overflow-x: auto; }
.table-toolbar { display: flex; align-items: center; gap: 1rem; min-height: 1.8rem; margin-bottom: 0.4rem; }
.panel--narrow { max-width: 560px; }

/* ---------- Excel-style filter menus (table_filter_controller.js) ---------- */
.table-filter__header { white-space: nowrap; }
.table-filter__sort { margin-left: 0.15rem; color: var(--color-primary); }
.table-filter__toggle {
  margin-left: 0.2rem;
  padding: 0 0.3rem;
  font-size: 0.65rem;
  line-height: 1.5;
  color: var(--color-muted);
  vertical-align: middle;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  cursor: pointer;
}
.table-filter__toggle:hover { color: var(--color-text); }
.table-filter__header.is-filtered .table-filter__toggle { color: #fff; background: var(--color-primary); border-color: var(--color-primary); }
.table-filter__panel {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 260px;
  padding: 0.5rem;
  font-size: 0.85rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}
.table-filter__menu-item {
  padding: 0.3rem 0.4rem;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
.table-filter__menu-item:hover { background: var(--color-bg); }
.table-filter__separator { width: 100%; margin: 0.15rem 0; border: 0; border-top: 1px solid var(--color-border); }
.table-filter__search { padding: 0.3rem 0.5rem; font-size: 0.85rem; }
.table-filter__list {
  max-height: 240px;
  overflow-y: auto;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}
.table-filter__option { display: flex; align-items: center; gap: 0.4rem; padding: 0.1rem 0; font-weight: normal; cursor: pointer; }
.table-filter__option[hidden] { display: none; }
.table-filter__option input { width: auto; }
.table-filter__actions { display: flex; justify-content: flex-end; gap: 0.35rem; }
.table tr[hidden] { display: none; }
/* The row just edited, when coming back to a list (table_filter_controller.js) */
.table tr.is-focused td { animation: table-row-focus 2.5s ease-out; }
@keyframes table-row-focus { from { background: #fff1b8; } to { background: transparent; } }

.table th.table__number, .table td.table__number { text-align: right; white-space: nowrap; }
.table__nowrap { white-space: nowrap; }
.table tr.is-alert td { background: var(--color-alert-bg); }
.table tr.is-selected td { font-weight: bold; background: var(--color-bg); }

/* ---------- Monthly limits and usage ---------- */
.limit--reached { font-weight: bold; color: var(--color-alert-text); }
.limit-badge {
  display: inline-block;
  margin-top: 0.15rem;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  color: #7a5200;
  white-space: nowrap;
  background: #fff8e5;
  border-radius: 999px;
}
.limit-badge--reached { color: var(--color-alert-text); background: var(--color-alert-bg); }
.page-header__actions { display: flex; align-items: center; gap: 0.5rem; }
.inline-form { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.inline-form__select { width: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 0.4rem; }
.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.stat__label { font-size: 0.8rem; color: var(--color-muted); }
.stat__value { font-size: 1.3rem; font-weight: bold; }
.stat__sub { font-size: 0.8rem; color: var(--color-muted); }
.usage-note { margin: 0 0 1.5rem; font-size: 0.8rem; }
.section-title { margin: 1.5rem 0 0.5rem; font-size: 1rem; }
.usage-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0 1.5rem; }
.dialog__footer { margin: 0; padding: 0 1.25rem 1rem; text-align: right; }

/* ---------- Manuals ---------- */
.form__checks--column { flex-direction: column; gap: 0.3rem; }
.manual-budget { margin: 0.25rem 0 0; font-size: 0.85rem; font-weight: bold; }
.manual-budget--over { color: var(--color-alert-text); }
.manual-error { color: var(--color-alert-text); }
.manual-warning { color: #7a5200; }
.manual-text__summary p { margin: 0 0 0.4rem; }
.manual-text__page { margin-top: 1rem; }
.manual-text__body {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.table__actions { text-align: right; white-space: nowrap; }
.table__actions form { display: inline; margin: 0; }
.table__actions > * + * { margin-left: 0.25rem; }
