:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: #152035;
  background: #f9fafc;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 320px; margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .6; }
:focus-visible { outline: 2px solid #2f6de0; outline-offset: 2px; }

.site-header { min-height: 59px; border-bottom: 1px solid #e3e7ee; background: #fff; }
.header-inner { max-width: 1440px; min-height: 59px; margin: auto; padding: 0 28px; display: flex; align-items: center; gap: 27px; }
.brand { color: #142037; font-size: 20px; font-weight: 700; letter-spacing: -.025em; text-decoration: none; }
.navigation { display: flex; align-items: center; gap: 30px; height: 100%; margin-left: auto; }
.nav-link, .logout-button { border: 0; background: none; color: #566278; font-size: 14px; font-weight: 550; padding: 9px 0; }
.nav-link:hover, .logout-button:hover { color: #255bc6; }
.nav-link.active { color: #142037; }
.nav-count { color: #718096; font-size: 12px; }
.account-name { max-width: 150px; padding-left: 27px; border-left: 1px solid #dce2eb; color: #526077; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-button { margin-left: 3px; }

.main-content { max-width: 1440px; margin: 0 auto; padding: 38px 28px 90px; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 28px; }
.workspace-main { grid-column: 1; min-width: 0; }
#archive-view, #admin-view { grid-column: 1 / -1; }
.add-section { margin-bottom: 54px; }
.section-title { display: block; margin: 0 0 12px; font-size: 23px; line-height: 1.28; font-weight: 680; letter-spacing: -.025em; }
.section-heading { margin-bottom: 19px; }
.section-heading .section-title { margin-bottom: 6px; }
.section-caption { margin: 0; color: #637087; font-size: 14px; line-height: 1.5; }
.count-badge { display: inline-block; min-width: 30px; margin-left: 7px; padding: 3px 8px; vertical-align: 2px; border-radius: 16px; background: #e8ebf0; color: #40516b; font-size: 14px; font-weight: 600; letter-spacing: 0; text-align: center; }

.flag-form { display: flex; align-items: center; gap: 8px; width: 100%; height: 54px; padding: 5px 9px 5px 16px; border: 1px solid #cbd4e2; border-radius: 5px; background: #fff; }
.flag-form:focus-within { border-color: #4b7ce0; box-shadow: 0 0 0 2px rgba(75,124,224,.11); }
.flag-form input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: #172033; font-size: 16px; }
.flag-form input::placeholder { color: #909bad; opacity: 1; }
.enter-button { flex: none; padding: 6px 9px; border: 1px solid #e1e6ed; border-radius: 4px; background: #f3f5f8; color: #687589; font-size: 13px; }
.enter-button:hover { background: #e9eef6; color: #245bc5; }
.enter-button span { margin-left: 3px; }
.inline-message { margin: 8px 0 0; color: #45617c; font-size: 13px; line-height: 1.5; }
.inline-message.error { color: #a43838; }
.inline-message.success { color: #28734b; }

.table-wrap { overflow-x: auto; border: 1px solid #dce2eb; border-radius: 5px; background: #fff; }
.flags-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.flags-table th { padding: 14px 20px; background: #f7f8fa; color: #566278; font-size: 13px; font-weight: 600; text-align: left; }
.flags-table td { padding: 15px 20px; border-top: 1px solid #e5e9ef; color: #172033; font-size: 14px; vertical-align: middle; }
.queue-table th:first-child, .queue-table td:first-child { width: 21%; }
.queue-table th:nth-child(2), .queue-table td:nth-child(2) { width: 43%; }
.queue-table th:last-child, .queue-table td:last-child { width: 36%; }
.archive-table th:first-child, .archive-table td:first-child { width: 45%; }
.archive-table th:nth-child(2), .archive-table td:nth-child(2) { width: 16%; }
.archive-table th:nth-child(3), .archive-table td:nth-child(3) { width: 20%; }
.archive-table th:last-child, .archive-table td:last-child { width: 19%; }
.flag-value { display: inline-block; max-width: 100%; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; user-select: all; }
.status-badge { display: inline-block; padding: 5px 9px; border-radius: 4px; background: #eff1f5; color: #536177; font-size: 12px; font-weight: 600; line-height: 1.3; }
.status-badge.active { background: #e5eefa; color: #1e5dbb; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 7px 12px; border: 1px solid #cdd5e1; border-radius: 4px; background: #fff; color: #344156; font-size: 13px; font-weight: 550; line-height: 1.15; white-space: nowrap; }
.button:hover { border-color: #b6c5dc; background: #f5f8fc; }
.button-primary { border-color: #2e69d5; background: #2e69d5; color: #fff; }
.button-primary:hover { border-color: #2459bd; background: #2459bd; }
.copy-button.copied { border-color: #abc4ea; background: #ecf3ff; color: #225dbc; }
.delete-button { border-color: #e2c9c9; color: #963b3b; }
.delete-button:hover { border-color: #cfa9a9; background: #fcf5f5; }
.done-button { min-width: 86px; }
.date-text { color: #627087 !important; font-size: 13px !important; white-space: nowrap; }
.empty-state { padding: 23px 20px; border: 1px solid #dce2eb; border-radius: 5px; background: #fff; color: #66748a; font-size: 14px; }
.empty-state p { margin: 0; }
.text-button { border: 0; background: none; padding: 0; color: #285fc5; font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }

.turn-panel { grid-column: 2; grid-row: 1; padding: 19px 20px 22px; border: 1px solid #dce2eb; border-radius: 6px; background: #fff; }
.turn-panel h2 { margin: 0 0 24px; font-size: 19px; line-height: 1.25; font-weight: 680; letter-spacing: -.02em; }
.turn-current { display: flex; align-items: flex-start; gap: 14px; min-height: 60px; }
.turn-dot { flex: none; width: 17px; height: 17px; margin-top: 5px; border-radius: 50%; background: #246be4; }
.turn-dot.inactive { background: #c6cfda; }
.turn-current strong { display: block; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.turn-current p { margin: 5px 0 0; color: #718096; font-size: 14px; }
.last-done { margin: 20px 0 0; padding: 17px 0; border-top: 1px solid #e7ebf0; border-bottom: 1px solid #e7ebf0; color: #647188; font-size: 13px; line-height: 1.45; }
.last-done strong { color: #172033; }
.participant-section { margin-top: 19px; }
.participant-section h3 { margin: 0 0 12px; color: #657289; font-size: 13px; font-weight: 600; }
.participants-list { margin: 0; padding: 0; list-style: none; }
.participants-list li { padding: 4px 0; color: #28354c; font-size: 14px; overflow-wrap: anywhere; }
.participants-list li.you { color: #1762cb; font-weight: 650; }

.admin-view { max-width: 1030px; }
.members-form { width: min(100%, 550px); }
.members-form label, .login-form label, .message-label { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 600; }
.members-form textarea, .login-form input, .telegram-message { width: 100%; border: 1px solid #cbd4e2; border-radius: 4px; background: #fff; color: #172033; outline: none; }
.members-form textarea:focus, .login-form input:focus, .telegram-message:focus { border-color: #4b7ce0; box-shadow: 0 0 0 2px rgba(75,124,224,.11); }
.members-form textarea { min-height: 140px; padding: 10px 12px; resize: vertical; font-size: 15px; line-height: 1.5; }
.field-help { margin: 9px 0 0; color: #647188; font-size: 13px; line-height: 1.5; }
.settings-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 13px; margin-top: 15px; }
.settings-actions .inline-message { margin: 0; }
.credentials-section { margin-top: 44px; scroll-margin-top: 24px; }
.credentials-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.credentials-heading .section-title { margin-bottom: 5px; }
.credentials-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 25px; }
.credential-card { min-width: 0; padding: 16px; border: 1px solid #dce2eb; border-radius: 5px; background: #fff; }
.credential-card h3 { margin: 0 0 13px; font-size: 15px; overflow-wrap: anywhere; }
.credential-field { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 8px; margin-top: 8px; }
.credential-label { color: #66748a; font-size: 12px; }
.credential-field code { min-width: 0; padding: 8px; border-radius: 3px; background: #f5f7fa; font-family: Consolas, "Courier New", monospace; font-size: 13px; overflow-wrap: anywhere; user-select: all; }
.credential-field .button { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.telegram-message { display: block; min-height: 220px; padding: 12px; resize: vertical; font-family: Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.5; }

.login-view { display: grid; min-height: 100dvh; place-items: center; padding: 22px; }
.login-panel { width: min(100%, 360px); padding: 30px; border: 1px solid #dce2eb; border-radius: 6px; background: #fff; box-shadow: 0 8px 30px rgba(27,42,70,.045); }
.login-mark { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 4px; background: #e8eefb; color: #315fc5; font-size: 17px; font-weight: 700; }
.login-panel h1 { margin: 18px 0 4px; font-size: 23px; }
.muted { color: #657186; }
.login-panel .muted { margin: 0 0 25px; font-size: 14px; }
.login-form label:not(:first-child) { margin-top: 13px; }
.login-form input { height: 42px; padding: 8px 11px; }
.login-form .button { width: 100%; min-height: 40px; margin-top: 18px; }
.form-error { margin: 13px 0 0; color: #a33838; font-size: 13px; line-height: 1.4; }
.loading-view { display: grid; min-height: 100dvh; place-items: center; color: #6b778a; font-size: 14px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: min(360px, calc(100vw - 40px)); padding: 11px 15px; border: 1px solid #cdd6e4; border-radius: 4px; background: #fff; color: #27354d; box-shadow: 0 8px 28px rgba(24,39,66,.12); font-size: 13px; }
.toast.error { border-color: #e3b7b7; color: #9e3333; }

@media (max-width: 950px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; }
  .turn-current strong { font-size: 19px; }
  .queue-table th:first-child, .queue-table td:first-child { width: 24%; }
  .queue-table th:nth-child(2), .queue-table td:nth-child(2) { width: 37%; }
  .queue-table th:last-child, .queue-table td:last-child { width: 39%; }
  .flags-table th, .flags-table td { padding-left: 12px; padding-right: 12px; }
}

@media (max-width: 720px) {
  .header-inner { flex-wrap: wrap; gap: 0 16px; padding: 0 17px; }
  .navigation { order: 3; width: 100%; min-height: 40px; gap: 24px; margin-left: 0; }
  .account-name { margin-left: auto; }
  .main-content { padding: 28px 17px 70px; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .workspace-main, #archive-view, #admin-view, .turn-panel { grid-column: 1; }
  .turn-panel { grid-row: auto; }
  .add-section { margin-bottom: 39px; }
  .section-title { font-size: 21px; }
  .flags-table thead { display: none; }
  .flags-table, .flags-table tbody, .flags-table tr, .flags-table td { display: block; width: 100% !important; }
  .flags-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 14px; border-top: 1px solid #e5e9ef; }
  .flags-table tr:first-child { border-top: 0; }
  .flags-table td { padding: 0; border: 0; }
  .queue-table td.row-status { grid-column: 1 / -1; }
  .queue-table td.row-flag, .archive-table td.row-flag { grid-column: 1 / -1; }
  .flags-table td.row-action-cell { grid-column: 1 / -1; }
  .row-actions { justify-content: flex-start; }
  .archive-table td.row-nickname, .archive-table td.row-date { grid-column: 1 / -1; color: #657188; font-size: 13px; }
  .archive-table td.row-nickname::before { content: "Сдал: "; color: #8793a5; }
  .archive-table td.row-date::before { content: "Когда: "; color: #8793a5; }
  .credentials-list { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .navigation { gap: 17px; }
  .nav-link, .account-name, .logout-button { font-size: 13px; }
  .account-name { max-width: 92px; padding-left: 12px; }
  .flag-form { padding-left: 11px; }
  .flag-form input { font-size: 14px; }
  .flag-form input::placeholder { font-size: 13px; }
  .credentials-heading { display: block; }
  .credentials-heading .button { margin-top: 12px; }
  .credential-field { grid-template-columns: 49px minmax(0, 1fr); }
  .credential-field .button { grid-column: 2; justify-self: start; }
}
