:root {
  color-scheme: light;
  --red: #b42318;
  --red-dark: color-mix(in srgb, var(--red) 84%, #000);
  --ink: #171717;
  --muted: #6d6d6d;
  --line: #e5e5e5;
  --soft: #f5f5f5;
  --white: #ffffff;
  --shadow: 0 18px 50px rgba(20, 20, 20, 0.09);
}

* { box-sizing: border-box; }

html { font-family: Montserrat, Inter, "Segoe UI", Arial, sans-serif; background: #f3f3f3; color: var(--ink); }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.app-header {
  min-height: 92px;
  padding: 18px clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.header-actions form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 9px; min-width: 0; padding-right: 6px; }
.user-chip > span:last-child { display: grid; line-height: 1.15; }
.user-chip strong { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.user-chip small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.user-avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: #f2e6e6; color: var(--red); font-size: 13px; font-weight: 800; }
.brand-mark {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--red);
  color: var(--white);
  font-family: Georgia, serif;
  font-size: 28px;
  font-weight: 700;
}
.brand-logo {
  width: 76px;
  height: 54px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
}
.brand-logo img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(22px, 2vw, 30px); letter-spacing: -.035em; }

main { padding: 28px clamp(18px, 4vw, 64px) 48px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.month-navigation, .toolbar-actions { display: flex; align-items: center; gap: 10px; }
.month-navigation h2 { min-width: 230px; margin: 0 4px; font-size: clamp(22px, 2.4vw, 34px); letter-spacing: -.04em; text-transform: capitalize; }
.month-summary { margin: 0 8px 0 0; color: var(--muted); font-size: 13px; }

.button, .icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 700;
  transition: .16s ease;
}
.button { padding: 0 16px; font-size: 13px; }
.icon-button { width: 42px; padding: 0; background: var(--white); border-color: var(--line); color: var(--ink); font-size: 25px; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button-primary { background: var(--red); color: var(--white); }
.button-primary:hover { background: var(--red-dark); }
.button-secondary { background: var(--white); border-color: var(--line); color: var(--ink); }
.button-secondary:hover, .button-quiet:hover { border-color: #c8c8c8; background: #fafafa; }
.button-quiet { background: transparent; color: var(--muted); }
.button-danger { background: #fff0f0; color: #a40000; border-color: #ffd2d2; }

.notice { margin: -4px 0 16px; padding: 11px 14px; border-radius: 10px; background: #fff8dc; color: #66520a; font-size: 13px; }
.is-hidden { display: none !important; }

.calendar-panel { overflow: hidden; background: var(--white); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.weekday-row, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekday-row { background: #1d1d1d; color: var(--white); }
.weekday-row span { padding: 11px 12px; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.calendar-grid { background: var(--line); gap: 1px; }
.day-cell { min-height: 168px; padding: 10px; background: var(--white); min-width: 0; }
.day-cell.is-outside { background: #fafafa; }
.day-cell.is-outside .date-number { color: #aaa; }
.day-cell.is-today { box-shadow: inset 0 0 0 2px var(--red); }
.day-header { min-height: 29px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.date-number { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 800; }
.today-label { color: var(--red); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.day-add { width: 27px; height: 27px; border: 0; border-radius: 8px; background: #f0f0f0; color: #555; opacity: 0; transition: .15s ease; }
.day-cell:hover .day-add, .day-add:focus-visible, .day-cell.is-empty .day-add { opacity: 1; }
.day-add:hover { background: var(--red); color: var(--white); }
.publication-list { display: grid; gap: 7px; }
.publication-card {
  width: 100%;
  border: 1px solid #e6e6e6;
  border-left: 4px solid var(--rubric-color, var(--red));
  border-radius: 9px;
  background: #fff;
  padding: 8px 9px;
  text-align: left;
  color: var(--ink);
}
.publication-card:hover { border-color: #cfcfcf; box-shadow: 0 5px 14px rgba(0,0,0,.06); }
.publication-rubric { display: block; margin-bottom: 4px; color: var(--rubric-color, var(--red)); font-size: 9px; font-weight: 800; letter-spacing: .055em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publication-theme { display: block; margin-bottom: 3px; color: #5d6470; font-size: 8px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publication-title { display: block; font-size: 12px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.publication-meta { display: block; margin-top: 6px; color: #555; font-size: 9px; line-height: 1.35; }
.publication-author { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.25; }
.empty-hint { margin: 23px 0 0; color: #b0b0b0; font-size: 11px; text-align: center; }

.dialog { width: min(590px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 17px; box-shadow: 0 30px 100px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(12,12,12,.52); backdrop-filter: blur(3px); }
.dialog-wide { width: min(940px, calc(100vw - 28px)); }
.dialog-extra-wide { width: min(1040px, calc(100vw - 28px)); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 23px 24px 17px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin-bottom: 0; font-size: 24px; letter-spacing: -.035em; }
.dialog-body { padding: 22px 24px; }
.dialog-footer { display: flex; align-items: center; gap: 9px; padding: 15px 24px 22px; }
.footer-spacer { flex: 1; }
.field, .field-row { display: grid; gap: 8px; }
.field + .field, .field-row + .field, .field + .field-row { margin-top: 17px; }
.field-row { grid-template-columns: 1fr 1fr; gap: 14px; }
.field > span { font-size: 12px; font-weight: 800; }
input, select, textarea { width: 100%; border: 1px solid #d8d8d8; border-radius: 10px; background: #fff; color: var(--ink); outline: none; }
input, select { min-height: 44px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(199,0,0,.09); }
.check-field { display: flex; align-items: center; gap: 9px; margin-top: 17px; font-size: 12px; font-weight: 700; }
.check-field input { width: 18px; min-height: 18px; margin: 0; }

.manage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.manage-section + .manage-section { border-left: 1px solid var(--line); padding-left: 28px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; }
.section-heading h3 { margin-bottom: 13px; font-size: 18px; }
.section-heading span { color: var(--muted); font-size: 11px; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.rubric-form { grid-template-columns: 44px 1fr auto; }
.color-input { padding: 5px; }
.manage-list { display: grid; gap: 7px; max-height: 340px; overflow: auto; }
.manage-item { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 8px 10px; border-radius: 9px; background: var(--soft); }
.manage-item-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 700; }
.color-dot { width: 12px; height: 12px; flex: 0 0 auto; border-radius: 50%; background: var(--item-color, var(--red)); }
.mini-button { border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.mini-button:hover { color: var(--red); }

.toast { position: fixed; z-index: 20; right: 22px; bottom: 22px; max-width: 360px; padding: 12px 16px; border-radius: 11px; background: #191919; color: #fff; box-shadow: var(--shadow); font-size: 13px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

.login-page { min-height: 100vh; background: #ededed; }
.login-layout {
  min-height: 100vh;
  padding: 28px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(199, 0, 0, .04), transparent 44%),
    #ededed;
}
.login-card { width: min(450px, 100%); padding: clamp(28px, 5vw, 46px); border-radius: 20px; background: var(--white); box-shadow: 0 28px 80px rgba(20,20,20,.12); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.login-brand h1 { font-size: 27px; }
.login-intro { margin-bottom: 25px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.login-form { display: grid; gap: 17px; }
.login-form .field + .field { margin-top: 0; }
.login-submit { width: 100%; min-height: 48px; margin-top: 3px; }
.login-note { margin: 22px 0 0; color: #999; font-size: 11px; text-align: center; }
.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 92px; }
.password-toggle { position: absolute; top: 50%; right: 7px; min-height: 32px; padding: 0 8px; border: 0; border-radius: 7px; transform: translateY(-50%); background: #f2f2f2; color: #555; font-size: 11px; font-weight: 700; }
.form-message { margin-bottom: 18px; padding: 11px 13px; border-radius: 9px; font-size: 12px; line-height: 1.45; }
.form-message-error { border: 1px solid #f1c4c4; background: #fff2f2; color: #8d0000; }
.form-message-success { border: 1px solid #bfe4cb; background: #eefaf2; color: #22623a; }

.manage-tabs {
  display: flex;
  gap: 5px;
  padding: 12px 24px 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}
.manage-tab {
  min-height: 40px;
  padding: 0 15px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.manage-tab.is-active { border-bottom-color: var(--red); color: var(--ink); }
.manage-panels { min-height: 390px; }
.manage-panel { display: none; }
.manage-panel.is-active { display: block; }
.panel-intro { margin: -3px 0 17px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.color-reference-form { grid-template-columns: 48px 1fr auto; }
.manage-empty { margin: 8px 0; color: #999; font-size: 13px; }
.mini-button-danger:hover { color: #b00000; }
.user-details { display: grid; gap: 3px; }
.user-details strong { font-size: 13px; }
.user-details small { color: var(--muted); font-size: 10px; font-weight: 500; }

.settings-form { display: grid; gap: 17px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.settings-form .field + .field { margin-top: 0; }
.color-setting { width: 180px; }
.color-setting input { min-height: 50px; padding: 5px; }
.settings-form > .button { justify-self: start; }
.logo-settings { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: 24px; padding-top: 24px; }
.logo-preview { min-height: 132px; display: grid; place-items: center; padding: 18px; border: 1px dashed #cfcfcf; border-radius: 12px; background: #fafafa; color: #999; font-size: 12px; text-align: center; }
.logo-preview img { display: block; max-width: 100%; max-height: 100px; object-fit: contain; }
.logo-form { display: grid; align-content: start; gap: 12px; }
.logo-form .field + .field { margin-top: 0; }
.field-help { margin: -4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.installer-page { min-height: 100vh; background: #ededed; }
.installer-layout { min-height: 100vh; display: grid; place-items: center; padding: 30px 18px; }
.installer-card { width: min(820px, 100%); padding: clamp(26px, 4vw, 46px); border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.brand-mark-generic { background: #273142; }
.installer-form { display: grid; gap: 24px; }
.installer-form fieldset { display: grid; gap: 17px; margin: 0; padding: 20px; border: 1px solid var(--line); border-radius: 13px; }
.installer-form legend { padding: 0 8px; font-size: 14px; font-weight: 800; }
.installer-form .field + .field { margin-top: 0; }
.installer-submit { min-height: 50px; font-size: 14px; }

@media (max-width: 1000px) {
  .toolbar { align-items: flex-start; }
  .toolbar-actions { align-items: flex-end; flex-direction: column-reverse; }
  .day-cell { min-height: 150px; padding: 8px; }
  .publication-card { padding: 7px; }
  .user-chip > span:last-child { display: none; }
}

@media (max-width: 720px) {
  .app-header { min-height: auto; padding: 15px 17px; align-items: flex-start; }
  .brand-mark { width: 43px; height: 43px; border-radius: 11px; font-size: 24px; }
  .brand-logo { width: 58px; height: 43px; }
  .app-header .button { width: 43px; padding: 0; font-size: 0; }
  .app-header .button span { font-size: 18px; }
  .header-actions { gap: 5px; }
  .user-chip { padding-right: 0; }
  .app-header .logout-button { width: auto; padding: 0 8px; font-size: 10px; }
  main { padding: 20px 14px 36px; }
  .toolbar { display: grid; gap: 13px; }
  .month-navigation { display: grid; grid-template-columns: 42px 42px 1fr auto; }
  .month-navigation h2 { min-width: 0; font-size: 23px; }
  .toolbar-actions { display: grid; grid-template-columns: 1fr; align-items: stretch; }
  .month-summary { order: 2; margin: 0; text-align: center; }
  .weekday-row { display: none; }
  .calendar-grid { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 10px; background: #f1f1f1; }
  .day-cell { min-height: 0; border-radius: 11px; padding: 11px; }
  .day-cell.is-outside { display: none; }
  .day-add { opacity: 1; }
  .publication-list { margin-top: 5px; }
  .empty-hint { margin: 9px 0 3px; text-align: left; }
  .field-row, .manage-grid { grid-template-columns: 1fr; }
  .manage-section + .manage-section { border-left: 0; border-top: 1px solid var(--line); padding: 24px 0 0; }
  .dialog-body { max-height: 68vh; overflow: auto; }
  .dialog-footer { flex-wrap: wrap; }
  .button-danger { order: 3; width: 100%; }
  .login-layout { padding: 14px; }
  .login-card { padding: 27px 22px; border-radius: 16px; }
  .login-brand h1 { font-size: 24px; }
  .manage-tabs { padding-left: 15px; padding-right: 15px; }
  .manage-panels { min-height: 0; }
  .color-reference-form { grid-template-columns: 46px 1fr; }
  .color-reference-form .button { grid-column: 1 / -1; }
  .logo-settings { grid-template-columns: 1fr; }
  .installer-card { padding: 25px 18px; }
  .installer-form fieldset { padding: 17px 14px; }
}
