@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #fafafa;
  --card: #fff;
  --border: #eaeaea;
  --text: #171717;
  --text2: #666;
  --text3: #555;
  --accent: #000;
  --accent-hover: #333;
  --danger: #e00;
  --success: #0a0;
  --blue: #0070f3;
  --radius: 8px;
  --radius-sm: 6px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.layout { min-height: 100vh; display: flex; flex-direction: column; }

/* header */
header { padding: 12px 24px; background: #000; color: #fff; border-bottom: 1px solid #333; }
.header__content { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 1200px; margin: 0 auto; }
header h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
header p { margin: 2px 0 0; color: #888; font-size: 12px; }
.header__user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #999; }
.header__user button { background: transparent; border: 1px solid #444; color: #ccc; padding: 5px 12px; border-radius: var(--radius-sm); font-size: 12px; cursor: pointer; transition: all .15s; }
.header__user button:hover { border-color: #888; color: #fff; }

/* auth */
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; margin-top: -40px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 100%; max-width: 380px; }

/* main */
main { flex: 1; padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 20px; }
.is-hidden { display: none !important; }

/* panel */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel__title { font-weight: 600; font-size: 13px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }

/* fields */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field span { font-size: 13px; font-weight: 500; color: var(--text2); }
.field input, .field textarea, .field select {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: 14px; background: var(--card); font-family: inherit; transition: border-color .15s;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: #000; }
.field input, .field textarea, .field select { -webkit-appearance: none; }
form button[type=submit] { -webkit-appearance: none; appearance: none; }
.field textarea { resize: vertical; }
.field select { cursor: pointer; }
.field-hint { font-size: 12px; color: var(--text3); }
.notice { min-height: 18px; font-size: 13px; color: var(--danger); margin-bottom: 6px; }

/* buttons */
button {
  all: unset; box-sizing: border-box; cursor: pointer;
  border-radius: var(--radius-sm); background: var(--accent); color: #fff;
  padding: 8px 16px; font-weight: 500; font-size: 13px;
  text-align: center; display: inline-flex; justify-content: center;
  max-width: 100%; transition: background .15s;
  border: 1px solid transparent;
  -webkit-appearance: none; -webkit-tap-highlight-color: rgba(0,0,0,.1); touch-action: manipulation;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: .35; cursor: not-allowed; }
.button-full { width: 100%; margin-bottom: 12px; }
.button-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.button-danger:hover { background: var(--danger); color: #fff; }
.button-sm { padding: 4px 10px; font-size: 12px; border-radius: 4px; }
.button-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.button-secondary:hover { background: #000; color: #fff; border-color: #000; }

/* settings */
.settings-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.settings-panel textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; background: var(--card);
  font-family: 'Geist Mono', 'SF Mono', 'Menlo', monospace; resize: vertical;
  outline: none; transition: border-color .15s;
}
.settings-panel textarea:focus { border-color: #000; }
.counter { font-weight: 400; font-size: 12px; color: var(--text3); text-transform: none; letter-spacing: 0; }
.counter--over { color: var(--danger); font-weight: 600; }
.expired-banner { background: #fff0f0; color: var(--danger); padding: 12px 20px; border-radius: var(--radius); font-weight: 600; font-size: 13px; text-align: center; border: 1px solid #fdd; }
.invalid-channels { background: #fff0f0; color: #c53030; padding: 12px 16px; border-radius: var(--radius); font-size: 13px; line-height: 1.6; border: 1px solid #fdd; margin-bottom: 12px; }
.invalid-channels strong { display: block; margin-bottom: 4px; font-size: 13px; }
.invalid-channels code { background: #fee2e2; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
/* tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tab { all: unset; box-sizing: border-box; cursor: pointer; padding: 10px 20px; font-size: 13px; font-weight: 500; color: var(--text3); border-bottom: 2px solid transparent; transition: all .15s; }
.tab:hover { color: #fff; background: #000; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab--active { color: var(--text); border-bottom-color: var(--accent); }

.save-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.fuzzy-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }
.fuzzy-toggle input { cursor: pointer; }
.save-status { font-size: 13px; }
.save-status--ok { color: var(--success); }
.save-status--err { color: var(--danger); }

/* table */
.messages-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.msg-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.msg-table thead { border-bottom: 2px solid var(--border); }
.msg-table th { padding: 8px 12px; text-align: left; font-weight: 500; color: var(--text2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.msg-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.msg-table tbody tr:hover { background: #f5f5f5; }
.msg-table td { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; position: relative; }
.msg-table tbody tr { cursor: pointer; }

/* msg modal */
.msg-modal-date { font-size: 12px; color: var(--text3); margin-bottom: 8px; font-family: 'Geist Mono', monospace; }
.msg-modal-group { font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.msg-modal-group a { color: var(--blue); }
.msg-modal-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.msg-modal-link { margin-top: 10px; font-size: 13px; }
.msg-modal-link a { color: var(--blue); }
.td-date { white-space: nowrap; color: var(--text3); font-size: 12px; font-family: 'Geist Mono', monospace; }
.kw-highlight { background: transparent; color: var(--success); font-weight: 700; }
.msg-table a { color: var(--blue); text-decoration: none; }
.msg-table a:hover { text-decoration: underline; }
.td-details { font-size: 12px; color: var(--text2); max-width: 500px; word-break: break-word; white-space: normal; }
.row-new { animation: fadeIn .4s; }
@keyframes fadeIn { from { background: #eef6ff; } to { background: transparent; } }
.empty-hint { font-size: 13px; color: var(--text3); text-align: center; padding: 32px 0; }

/* pagination */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.pagination button { padding: 4px 10px; font-size: 12px; border-radius: 4px; background: #fff; color: var(--text); border: 1px solid var(--border); }
.pagination button.pg-active { background: #000; color: #fff; border-color: #000; }
.pg-total { font-size: 12px; color: var(--text3); margin-left: 12px; }
.pagination-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; gap: 8px; }
.pagination-row .pagination { margin-top: 0; }
.page-size { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text3); }
.page-size select { border: 1px solid var(--border); border-radius: 4px; padding: 3px 6px; font-size: 12px; background: var(--card); cursor: pointer; outline: none; }

/* filters */
.filters-row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters-row .button-sm:first-of-type { margin-left: auto; }
.filter-field { display: flex; flex-direction: column; gap: 3px; }
.filter-field span { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: .04em; }
.filter-field input, .filter-field select { border: 1px solid var(--border); border-radius: 4px; padding: 5px 8px; font-size: 12px; background: var(--card); outline: none; font-family: inherit; }
/* channels modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 100%; max-width: 420px; }
.modal--sm { max-width: 340px; }
.modal__title { font-weight: 600; font-size: 15px; margin-bottom: 16px; }
.ch-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.ch-item { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.ch-item input { width: 16px; height: 16px; accent-color: #000; cursor: pointer; }

/* presets */
.preset-cat { margin-bottom: 16px; }
.preset-cat__title { font-weight: 600; font-size: 14px; margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 6px; user-select: none; }
.preset-cat__title:hover { color: var(--blue); }
.preset-cat__arrow { display: inline-block; width: 14px; font-size: 10px; transition: transform .15s; }
.preset-list { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; cursor: pointer; transition: all .15s; background: var(--card); }
.preset-card:hover { border-color: #000; background: #f5f5f5; }
.preset-card__name { font-weight: 500; font-size: 13px; }
.preset-card__meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
.view-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.view-label { font-weight: 600; font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.view-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12px; white-space: pre-line; max-height: 150px; overflow-y: auto; font-family: 'Geist Mono', monospace; }
.modal--wide { max-width: 700px; max-height: 85vh; overflow-y: auto; }

/* stream badge */
.stream-badge { font-size: 10px; font-weight: 600; padding: 2px 8px 2px 20px; border-radius: 20px; background: #eee; color: #999; text-transform: uppercase; letter-spacing: .05em; position: relative; }
.stream-badge::before { content: ''; position: absolute; left: 7px; top: 50%; transform: translateY(-50%); width: 7px; height: 7px; border-radius: 50%; background: #ccc; }
.stream-badge--active { background: #ecfdf5; color: #059669; }
.stream-badge--active::before { background: #059669; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* badge */
.toggle-row { flex-direction: row !important; align-items: center; gap: 10px !important; cursor: pointer; }
.toggle-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: #000; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.badge--admin { background: #eef; color: #33c; }
.badge--user { background: #f5f5f5; color: #666; }
.badge--blocked { background: #fff0f0; color: #e00; }
.badge--active { background: #ecfdf5; color: #059669; }
.row-actions { display: flex; gap: 4px; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

@media (max-width: 900px) {
  main { padding: 16px; }
  .settings-row { grid-template-columns: 1fr; }
}
