/* NChip ESP Flasher layout, aligned with the nMotion S21 dashboard.
   Local assets only. The Web Serial / flashing logic is not styled or changed here. */

:root {
  --nchip-bg: #f3f6fb;
  --nchip-panel: #ffffff;
  --nchip-panel-soft: #f7f9fc;
  --nchip-inset: #f3f6fb;
  --nchip-border: #e2e8f1;
  --nchip-border-strong: #cfd9e6;
  --nchip-text: #0f1d33;
  --nchip-muted: #5b6b85;
  --nchip-dim: #8a99b0;
  --nchip-blue: #0b74e5;
  --nchip-green: #16a34a;
  --nchip-orange: #ea8a06;
  --nchip-red: #dc2626;
  --nchip-log: #0f1726;
  --nchip-shadow: 0 6px 20px -12px rgba(15, 29, 51, .25);
  --nchip-radius: 12px;
}

/* Fonts are served locally from this project's public/fonts directory. */
@font-face {
  font-family: "NChip Roboto";
  src: url("./fonts/roboto-v27-latin/roboto-v27-latin-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "NChip Roboto";
  src: url("./fonts/roboto-v27-latin/roboto-v27-latin-700.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "NChip Mono";
  src: url("./fonts/roboto-mono-v13-latin/roboto-mono-v13-latin-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#root {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

html {
  background: var(--nchip-bg);
}

body {
  min-height: 100vh;
  color: var(--nchip-text);
  font-family: "NChip Roboto", Roboto, "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(1000px 500px at 90% -10%, rgba(11, 116, 229, .075), transparent 60%),
    linear-gradient(rgba(15, 29, 51, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 29, 51, .035) 1px, transparent 1px),
    var(--nchip-bg);
  background-size: auto, 32px 32px, 32px 32px, auto;
  -webkit-font-smoothing: antialiased;
}

/* The centered application frame mirrors the 1440px nMotion S21 container.
   The inline sx in App.js repeats this width as a fallback if a stylesheet is cached. */
#root > .app-shell.MuiBox-root,
.app-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: calc(100% - 36px) !important;
  max-width: 1440px !important;
  min-width: 0;
  margin: 10px auto 0 !important;
  padding: 0 0 22px !important;
  position: relative;
  z-index: 1;
}

/* nMotion-like header proportions and card treatment. */
.app-shell > .MuiAppBar-root {
  width: 100%;
  margin: 0 0 0 !important;
  border: 1px solid var(--nchip-border);
  border-radius: 14px !important;
  background: var(--nchip-panel) !important;
  color: var(--nchip-text) !important;
  box-shadow: var(--nchip-shadow);
}

.app-shell > .MuiAppBar-root::after {
  content: "";
  display: block;
  height: 2px;
  background: linear-gradient(90deg, var(--nchip-blue), var(--nchip-green), transparent);
}

.app-shell .MuiToolbar-root {
  min-height: 62px !important;
  padding-inline: 14px;
  gap: 12px;
}

.app-shell .MuiTypography-root {
  letter-spacing: normal;
}

.app-shell .MuiButton-root {
  min-height: 36px;
  border-radius: 8px;
  font-weight: 600;
  text-transform: none;
}

.app-shell .MuiOutlinedInput-root,
.app-shell .MuiFormControl-root .MuiInputBase-root {
  border-radius: 8px;
}

.app-shell .MuiAlert-root {
  border-radius: 10px;
}

.app-shell .MuiPaper-root {
  border-color: var(--nchip-border);
}

.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, .95fr);
  grid-template-areas:
    "home serial";
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.app-main > *,
.app-main .MuiPaper-root {
  min-width: 0;
  max-width: 100%;
}

.app-main:not(.is-connected) > .output-panel {
  grid-column: 1 / -1;
}

.home-card {
  grid-area: home;
  width: 100%;
  border-radius: var(--nchip-radius) !important;
  background: var(--nchip-panel);
  box-shadow: var(--nchip-shadow);
}

.serial-monitor-card {
  grid-area: serial;
  width: 100%;
  border-radius: var(--nchip-radius) !important;
  background: var(--nchip-panel);
  box-shadow: var(--nchip-shadow);
}


.connecting-panel {
  grid-column: 1 / -1;
  width: 100%;
  border-radius: var(--nchip-radius) !important;
  padding: 18px;
  background: var(--nchip-panel);
}

/* Connected dashboard: three cards aligned on one row, like nMotion Live Control. */
.app-main.is-connected {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "dashboard"
    "output";
  align-items: start;
}

.connected-layout {
  grid-area: dashboard;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, .92fr) minmax(0, 1.12fr);
  grid-template-areas: "firmware actions partition";
  align-items: stretch;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.firmware-card {
  grid-area: firmware;
}

.device-actions-card {
  grid-area: actions;
}

.partition-card {
  grid-area: partition;
}

.firmware-card,
.device-actions-card,
.partition-card {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--nchip-border) !important;
  border-radius: var(--nchip-radius) !important;
  background: var(--nchip-panel) !important;
  box-shadow: var(--nchip-shadow);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-width: 0;
  margin-bottom: 12px;
}

.panel-heading h2 {
  color: var(--nchip-text);
  font-size: 1rem;
  line-height: 1.35;
  font-weight: 800;
}

.panel-heading .MuiTypography-body2 {
  margin-top: 3px;
  line-height: 1.45;
  font-size: .82rem;
}

.device-action-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
  width: 100%;
}

.device-action-buttons > span {
  display: flex;
  min-width: 0;
}

.device-action-buttons .MuiButton-root {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  white-space: nowrap;
  padding-inline: 8px;
  font-size: .82rem;
}

.verify-control {
  display: flex;
  align-items: flex-start;
  margin: 10px 0 0 !important;
  padding: 8px 10px 8px 4px;
  border: 1px solid #e7edf5;
  border-radius: 9px;
  background: #f7f9fc;
}

.verify-control .MuiFormControlLabel-label {
  color: var(--nchip-muted);
  font-size: .78rem;
  line-height: 1.4;
}

.partition-card .MuiTableContainer-root {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--nchip-border);
  border-radius: 9px;
}

.partition-card .MuiTableCell-root {
  padding: 7px 9px;
  border-color: var(--nchip-border);
  font-size: .76rem;
  white-space: nowrap;
}

.partition-card .MuiAlert-root {
  padding-block: 7px;
  font-size: .75rem;
  line-height: 1.4;
}

/* Output log styled like the nMotion Activity Log card. */
.output-panel {
  grid-area: output;
  width: 100%;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--nchip-border);
  border-radius: var(--nchip-radius);
  background: var(--nchip-panel);
  box-shadow: var(--nchip-shadow);
}

.output-panel > .MuiFormControlLabel-root {
  display: flex;
  min-height: 38px;
  margin: 0;
  padding: 4px 10px;
  background: var(--nchip-panel-soft);
  border-bottom: 1px solid var(--nchip-border);
}

.output-panel .MuiTypography-root {
  color: var(--nchip-text);
  font-size: .86rem;
  font-weight: 800;
}

.app-shell footer {
  width: 100%;
  margin-top: 2px !important;
  padding-top: 8px !important;
  border-top: 1px solid var(--nchip-border);
}

/* General form and typography refinements. */
.app-shell .MuiInputBase-input {
  min-width: 0;
  font-size: .88rem;
}

.app-shell .MuiChip-root {
  font-weight: 600;
}

.app-shell .MuiTooltip-tooltip {
  font-size: .75rem;
}

@media (max-width: 1199px) {
  #root > .app-shell.MuiBox-root,
  .app-shell {
    max-width: 1080px !important;
  }

  .connected-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "firmware actions"
      "partition partition";
  }
}

@media (max-width: 900px) {
  .app-main:not(.is-connected) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "home"
      "serial";
  }

  .connected-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "firmware firmware"
      "actions partition";
  }
}

@media (max-width: 650px) {
  #root > .app-shell.MuiBox-root,
  .app-shell {
    width: calc(100% - 20px) !important;
    margin-top: 8px !important;
    padding-bottom: 16px !important;
  }

  .app-shell .MuiToolbar-root {
    min-height: 58px !important;
    padding-inline: 10px;
    gap: 8px;
  }

  .app-main,
  .app-main.is-connected,
  .connected-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "firmware"
      "actions"
      "partition"
      "output";
    gap: 9px;
  }

  .app-main:not(.is-connected) {
    grid-template-areas:
      "home"
      "serial";
  }

  .home-card,
  .serial-monitor-card,
  .firmware-card,
  .device-actions-card,
  .partition-card {
    padding: 12px !important;
    border-radius: 11px !important;
  }

  .panel-heading {
    flex-wrap: wrap;
    margin-bottom: 10px;
  }

  .device-action-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .device-action-buttons .MuiButton-root {
    min-height: 39px;
    font-size: .78rem;
  }
}

@media (max-width: 380px) {
  #root > .app-shell.MuiBox-root,
  .app-shell {
    width: calc(100% - 14px) !important;
  }

  .app-shell .MuiToolbar-root {
    padding-inline: 8px;
  }

  .device-action-buttons {
    grid-template-columns: minmax(0, 1fr);
  }
}
