:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #17252f;
  --muted: #687884;
  --line: #d7e2e0;
  --brand: #146c72;
  --brand-dark: #0f4f55;
  --warm: #f3b44b;
  --soft: #e8f4f3;
  --danger: #b44444;
  --shadow: 0 10px 24px rgba(23, 37, 47, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 42px);
}

h2 {
  font-size: 20px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1.35fr) minmax(320px, .9fr);
  gap: 16px;
  padding: 16px;
  max-width: 1480px;
  margin: 0 auto;
}

.tool-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.phrase-panel, .agenda-panel {
  grid-column: span 1;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.header-actions, .button-row, .search-box, .time-presets, .dict-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.compact {
  justify-content: flex-end;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 86px;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  min-height: 40px;
}

.primary-btn {
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
  font-weight: 800;
}

.secondary-btn {
  background: var(--soft);
  color: var(--brand-dark);
  border: 1px solid #b7d4d1;
  padding: 9px 12px;
  font-weight: 800;
}

.ghost-btn {
  background: #fff;
  color: var(--brand-dark);
  border: 1px solid var(--line);
  padding: 9px 12px;
  font-weight: 700;
}

.text-btn {
  background: #fff4df;
  color: #7d4d05;
  border: 1px solid #f0d19a;
  padding: 9px 12px;
  font-weight: 800;
}

.icon-btn {
  width: 42px;
  background: var(--soft);
  color: var(--brand-dark);
  border: 1px solid #b7d4d1;
  font-size: 19px;
}

.focus-btn {
  width: 38px;
  min-height: 34px;
  background: #fff;
  color: var(--brand-dark);
  border: 1px solid var(--line);
  font-size: 18px;
  font-weight: 900;
}

.exit-focus-btn {
  display: none;
  position: fixed;
  left: 18px;
  top: 18px;
  z-index: 20;
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 99px;
  padding: 3px 9px;
  background: #eef6ec;
  color: #2d6a35;
  border: 1px solid #cfe3cc;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.error {
  background: #fff0f0;
  border-color: #e5c2c2;
  color: var(--danger);
}

.sequence-toolbar {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.picto-sequence, .agenda-list, .favorites-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  min-height: 150px;
  border: 1px dashed #bfd0ce;
  border-radius: 8px;
  padding: 10px;
  background: #fbfdfd;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.picto-card {
  width: var(--tile-size, 128px);
  min-height: calc(var(--tile-size, 128px) + 34px);
  background: #fff;
  border: 2px solid #d8e2e0;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  position: relative;
}

.picto-card.label-top {
  grid-template-rows: auto 1fr;
}

.picto-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
}

.picto-label {
  min-height: 24px;
  border: 0;
  padding: 0;
  text-align: center;
  font-size: clamp(13px, 1.4vw, 17px);
  font-weight: 900;
  color: var(--ink);
  resize: none;
  overflow: hidden;
  line-height: 1.05;
  background: transparent;
}

.picto-actions {
  position: absolute;
  right: 5px;
  top: 5px;
  display: flex;
  gap: 3px;
}

.mini-btn {
  width: 26px;
  min-height: 26px;
  border-radius: 5px;
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  font-size: 13px;
}

.search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
  margin-top: 12px;
  max-height: 440px;
  overflow: auto;
  padding-right: 4px;
}

.compact-results {
  max-height: 260px;
}

.result-section-title {
  grid-column: 1 / -1;
  padding: 8px 2px 0;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.search-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 7px;
}

.search-result img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.search-result strong {
  display: block;
  text-align: center;
  font-size: 13px;
  min-height: 34px;
}

.search-result small {
  display: block;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.search-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

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

.search-actions button {
  min-height: 32px;
  font-size: 12px;
}

.library-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 420px;
  overflow: auto;
  padding-right: 4px;
}

.library-row {
  display: grid;
  grid-template-columns: 62px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.library-row img,
.library-row > .empty-state {
  width: 62px;
  aspect-ratio: 1;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdfd;
}

.library-row strong,
.library-row span,
.library-row small {
  display: block;
}

.library-row span,
.library-row small {
  color: var(--muted);
}

.library-row small {
  margin-top: 3px;
  line-height: 1.25;
}

.library-actions {
  display: grid;
  gap: 4px;
}

.picto-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.picto-form .full-row {
  grid-column: 1 / -1;
}

.picto-form input,
.picto-form select,
.picto-form textarea {
  margin-top: 5px;
  font-weight: 500;
}

.agenda-item {
  display: grid;
  gap: 6px;
}

.agenda-time {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.clock-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f9fcfb 100%);
}

.time-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.clock-display {
  display: grid;
  grid-template-columns: 132px 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.progress-ring {
  width: 126px;
  height: 126px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: #e5eceb;
  stroke-width: 12;
}

.ring-progress {
  fill: none;
  stroke: var(--warm);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset .35s ease;
}

.clock-copy strong {
  display: block;
  font-size: clamp(42px, 6vw, 70px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.clock-copy b {
  display: block;
  margin-top: 4px;
  color: var(--brand-dark);
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.clock-copy small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 800;
}

.clock-kicker {
  display: block;
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.linear-progress {
  grid-column: 1 / -1;
  width: 100%;
  height: 18px;
  margin-top: 10px;
  border-radius: 99px;
  overflow: hidden;
  background: #e5eceb;
}

.linear-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand), var(--warm));
  transition: width .35s ease;
}

.helper {
  color: var(--muted);
  margin: 0 0 10px;
}

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

.dictionary-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.dict-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 7px;
  align-items: center;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.credits {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 16px 26px;
  color: var(--muted);
  font-size: 12px;
}

body.focus-mode {
  background: #fff;
}

body.focus-mode .app-header,
body.focus-mode .credits {
  display: none;
}

body.focus-mode .exit-focus-btn {
  display: inline-flex;
  align-items: center;
}

body.focus-mode .workspace {
  display: block;
  max-width: none;
  min-height: 100vh;
  padding: 0;
}

body.focus-mode .tool-panel {
  display: none;
}

body.focus-mode .tool-panel.focused {
  display: block;
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 72px clamp(14px, 4vw, 48px) 28px;
}

body.focus-mode .tool-panel.focused .panel-heading {
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
}

body.focus-mode .phrase-panel.focused .picto-sequence,
body.focus-mode .agenda-panel.focused .agenda-list,
body.focus-mode .favorites-panel.focused .favorites-list {
  min-height: 58vh;
  justify-content: center;
  align-items: center;
}

body.focus-mode .phrase-panel.focused,
body.focus-mode .agenda-panel.focused {
  --tile-size: 164px;
}

body.focus-mode .clock-panel.focused {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  align-items: center;
}

body.focus-mode .clock-panel.focused .time-presets,
body.focus-mode .clock-panel.focused .time-fields {
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
}

body.focus-mode .clock-panel.focused .time-fields {
  grid-template-columns: 1fr 1fr 1fr;
}

body.focus-mode .clock-panel.focused .clock-display {
  max-width: 1100px;
  margin: 16px auto;
  grid-template-columns: 1fr;
  justify-items: center;
  text-align: center;
  padding: clamp(18px, 4vw, 48px);
  border-width: 2px;
}

body.focus-mode .clock-panel.focused .progress-ring {
  display: none;
}

body.focus-mode .clock-panel.focused .clock-copy strong {
  font-size: clamp(86px, 16vw, 220px);
}

body.focus-mode .clock-panel.focused .clock-copy b {
  font-size: clamp(42px, 7vw, 92px);
}

body.focus-mode .clock-panel.focused .clock-copy small {
  font-size: clamp(18px, 2.2vw, 30px);
}

body.focus-mode .clock-panel.focused .clock-kicker {
  font-size: clamp(13px, 1.4vw, 20px);
}

body.focus-mode .clock-panel.focused .linear-progress {
  max-width: 1100px;
  height: 34px;
  margin: 8px auto 0;
}

.loading {
  opacity: .65;
  pointer-events: none;
}

@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; }
  .app-header { position: static; align-items: flex-start; }
  .clock-display { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .dict-form, .picto-form { grid-template-columns: 1fr; }
  .library-row { grid-template-columns: 54px 1fr auto; }
  .library-row img,
  .library-row > .empty-state { width: 54px; }
  body.focus-mode .clock-panel.focused .time-fields {
    grid-template-columns: 1fr;
  }
  body.focus-mode .clock-panel.focused .clock-display {
    grid-template-columns: 1fr;
    text-align: center;
  }
}

@media print {
  .app-header, .search-panel, .library-panel, .picto-form-panel, .dictionary-panel, .favorites-panel, .button-row, .sequence-toolbar, .time-presets, .time-fields, .credits { display: none !important; }
  body { background: #fff; }
  .workspace { display: block; padding: 0; max-width: none; }
  .tool-panel { box-shadow: none; border: 0; page-break-inside: avoid; margin-bottom: 14px; }
  .picto-sequence, .agenda-list { border: 0; padding: 0; }
}
