:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #d8dee4;
  --line-strong: #b7c0ca;
  --text: #17212b;
  --muted: #5f6b78;
  --primary: #0877b9;
  --primary-dark: #065d91;
  --accent: #596052;
  --danger: #b3261e;
  --focus: #2a7de1;
  --row: #fbfcfd;
  --row-selected: #e5f3fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

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

button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--primary);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

button.primary:hover {
  background: var(--primary-dark);
}

button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.app-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 86px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 1px 8px rgba(23, 33, 43, 0.08);
  overflow: hidden;
}

.app-header::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 360px;
  background: url("/logo/dsmark_trans.png") center right -90px / 240px 240px no-repeat;
  opacity: 0.08;
  pointer-events: none;
}

.brand-block {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-logo {
  width: 286px;
  max-width: 36vw;
  height: 58px;
  object-fit: contain;
  object-position: left center;
  padding: 4px 14px 4px 0;
  border-right: 1px solid var(--line);
}

.app-header h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.header-actions {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-actions form {
  margin: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 4px;
  padding-right: 12px;
  border-right: 1px solid var(--line);
}

.user-chip img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: contain;
}

.user-chip span {
  display: grid;
  line-height: 1.2;
}

.user-chip small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.layout {
  padding: 14px 20px 20px;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) auto auto repeat(4, minmax(130px, 1fr)) auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px 0;
}

.field {
  display: grid;
  gap: 4px;
}

.field label,
.form-grid label,
.date-card label {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 34px;
  padding: 6px 8px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.segmented {
  display: flex;
  height: 34px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.segmented label {
  display: grid;
  place-items: center;
  min-width: 72px;
  padding: 0 10px;
  border-right: 1px solid var(--line);
  cursor: pointer;
}

.segmented label:last-child {
  border-right: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--primary);
  color: #fff;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  white-space: nowrap;
}

.check-line input {
  width: 16px;
  min-height: 16px;
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  min-height: 38px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.summary-strip strong {
  color: var(--text);
}

#message {
  color: var(--primary);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 14px;
  padding-top: 14px;
}

.table-wrap {
  min-height: 520px;
  max-height: calc(100vh - 210px);
  overflow: auto;
  border: 1px solid var(--line);
  background: #fff;
}

table {
  width: 100%;
  min-width: 1520px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf3f7;
  font-weight: 700;
  user-select: none;
}

th .resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
}

th.resizing,
body.resizing-columns {
  cursor: col-resize;
}

body.resizing-columns {
  user-select: none;
}

td.memo-cell {
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody tr {
  background: var(--row);
  cursor: pointer;
}

tbody tr:nth-child(even) {
  background: #fff;
}

tbody tr.selected {
  background: var(--row-selected);
}

.edit-panel {
  position: relative;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
  max-height: calc(100vh - 210px);
  overflow: auto;
}

.edit-panel::before {
  content: "";
  position: absolute;
  top: 14px;
  right: 14px;
  width: 54px;
  height: 54px;
  background: url("/logo/dsmark.jpg") center / contain no-repeat;
  opacity: 0.12;
  pointer-events: none;
}

.form-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.form-title h2 {
  margin: 0;
  font-size: 18px;
}

#selectedId {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 4px;
}

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

.date-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.date-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  align-items: center;
}

.date-card label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-card input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

.date-card input[type="date"]:disabled {
  background: #eef1f3;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 1180px) {
  .search-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .field.wide,
  .segmented {
    grid-column: span 2;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .edit-panel {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-block {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .brand-logo {
    max-width: 100%;
    width: 240px;
    height: auto;
    border-right: 0;
    padding-right: 0;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }

  .field.wide,
  .segmented {
    grid-column: auto;
  }

  .header-actions,
  .form-actions {
    flex-wrap: wrap;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* Login */
.login-page {
  min-height: 100vh;
  background: #eef3f6;
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(440px, 1.05fr) minmax(440px, 0.95fr);
  min-height: 100vh;
}

.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
  padding: clamp(34px, 5vw, 72px);
  overflow: hidden;
  color: #fff;
  background: linear-gradient(145deg, #006ca8 0%, #07577f 48%, #163c50 100%);
}

.login-brand::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 16% 78%, rgba(255, 255, 255, 0.13), transparent 28%), linear-gradient(115deg, transparent 48%, rgba(255,255,255,.04) 48% 49%, transparent 49%);
  pointer-events: none;
}

.login-brand-logo {
  position: relative;
  z-index: 1;
  width: min(340px, 65%);
  max-height: 74px;
  object-fit: contain;
  object-position: left center;
  padding: 9px 14px;
  border-radius: 8px;
  background: #fff;
}

.login-brand-copy {
  position: relative;
  z-index: 1;
  margin: auto 0;
  padding: 60px 0;
}

.login-eyebrow,
.login-kicker {
  color: #69c6ea;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.login-brand-copy h1 {
  margin: 20px 0 24px;
  font-size: clamp(36px, 4.2vw, 62px);
  line-height: 1.18;
  letter-spacing: -0.05em;
}

.login-brand-copy p {
  margin: 0;
  color: rgba(255,255,255,.72);
  font-size: 17px;
  line-height: 1.8;
}

.login-watermark {
  position: absolute;
  z-index: 0;
  right: -12%;
  bottom: -8%;
  width: min(520px, 72%);
  opacity: .1;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 42px;
  background: #fff;
}

.login-form-wrap {
  width: min(420px, 100%);
}

.login-symbol {
  display: block;
  width: 52px;
  height: 52px;
  margin-bottom: 28px;
  object-fit: contain;
  border-radius: 12px;
}

.login-form-wrap h2 {
  margin: 9px 0 10px;
  font-size: 32px;
  letter-spacing: -0.04em;
}

.login-description {
  margin: 0 0 30px;
  color: var(--muted);
  line-height: 1.65;
}

.login-alerts {
  margin-bottom: 18px;
}

.alert {
  padding: 12px 14px;
  border: 1px solid #f0c7c3;
  border-radius: 8px;
  color: #8e241d;
  background: #fff2f0;
  line-height: 1.45;
}

.alert-success {
  border-color: #bfe1d0;
  color: #17633e;
  background: #effaf4;
}

.login-form {
  display: grid;
  gap: 9px;
}

.login-form label {
  margin-top: 7px;
  color: #344450;
  font-size: 13px;
  font-weight: 700;
}

.login-input-wrap {
  position: relative;
}

.login-input-wrap svg {
  position: absolute;
  top: 50%;
  left: 15px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #81909c;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  transform: translateY(-50%);
  pointer-events: none;
}

.login-input-wrap input {
  min-height: 52px;
  padding: 10px 14px 10px 46px;
  border-color: #cdd7de;
  border-radius: 8px;
  background: #fbfcfd;
}

.login-input-wrap input:focus {
  border-color: var(--primary);
  background: #fff;
}

.login-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  margin-top: 17px;
  padding: 0 20px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(90deg, #0877b9, #075b8a);
  box-shadow: 0 10px 24px rgba(8, 119, 185, .2);
  font-weight: 700;
}

.login-submit:hover {
  background: linear-gradient(90deg, #066aa5, #064e77);
}

.login-submit span {
  font-size: 22px;
}

.login-help {
  margin: 24px 0 0;
  color: #87939c;
  font-size: 12px;
  text-align: center;
}

.error-panel {
  width: min(520px, calc(100% - 40px));
  margin: 15vh auto;
  padding: 42px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 55px rgba(20, 45, 60, .12);
  text-align: center;
}

.error-panel img { width: 250px; max-width: 80%; }
.error-panel a { color: var(--primary); font-weight: 700; }

@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 280px; padding: 30px; }
  .login-brand-copy { padding: 35px 0 10px; }
  .login-brand-copy h1 { margin: 12px 0; font-size: 34px; }
  .login-brand-copy p { display: none; }
  .login-brand-logo { width: 250px; max-height: 56px; }
  .login-panel { padding: 44px 24px; }
}

@media (max-width: 720px) {
  .user-chip { width: 100%; border-right: 0; padding: 0 0 8px; }
}
