:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --text-main: #f1f5f9;
  --accent: #38bdf8;
  --border-ui: #334155;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --breakpoint-mobile: 768px;
  --breakpoint-tablet: 1024px;
  box-sizing: border-box;
}

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

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  background-color: var(--bg-dark);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.top-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-ui);
  padding: 0 30px;
  height: 65px;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}

.nav-left {
  display: flex;
  justify-content: flex-start;
}
.nav-center {
  display: flex;
  justify-content: center;
}
.nav-right {
  display: flex;
  justify-content: flex-end;
  height: 100%;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  transition: var(--transition);
}

.nav-logo img {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 0 8px var(--accent));
}

.nav-logo span {
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.9rem;
}

.nav-logo:hover {
  transform: scale(1.03);
  opacity: 0.9;
}

.current-tool-title {
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: rgba(56, 189, 248, 0.1);
  padding: 8px 24px;
  border-radius: 50px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  white-space: nowrap;
  box-shadow: inset 0 0 10px rgba(56, 189, 248, 0.1);
}

.nav-links {
  display: flex;
  gap: 5px;
  height: 100%;
}

.nav-item {
  text-decoration: none;
  color: #94a3b8;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  padding: 0 15px;
  height: 100%;
  border-bottom: 3px solid transparent;
  transition: var(--transition);
  box-sizing: border-box;
}

.nav-item:hover {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.05);
}

.nav-item.active {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.tool-dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  min-width: 200px;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-ui);
  border-radius: 12px;
  z-index: 1100;
  margin-top: 10px;
  overflow: hidden;
  animation: fadeInDown 0.2s ease-out;
}

.tool-dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-header {
  background: rgba(56, 189, 248, 0.1);
  padding: 10px;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  border-bottom: 1px solid var(--border-ui);
}

.history-item {
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
  display: block;
  transition: background 0.2s;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  white-space: nowrap;
}

.history-item:hover {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
}

.empty-history {
  padding: 15px;
  display: block;
  font-size: 0.8rem;
  color: #64748b;
  text-align: center;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

button {
  width: 100%;
  padding: 15px;
  background: var(--accent);
  color: var(--bg-dark);
  border: none;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 1px;
}

button:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(56, 189, 248, 0.4);
}

button:disabled {
  cursor: not-allowed;
  background: #1e293b;
  color: #64748b;
}

@media (min-width: 769px) and (max-width: 1024px) {
  .top-nav {
    padding: 0 20px;
    height: 60px;
  }

  .nav-logo span {
    font-size: 0.8rem;
  }

  .nav-logo img {
    width: 28px;
    height: 28px;
  }

  .current-tool-title {
    font-size: 0.8rem;
    padding: 6px 18px;
    white-space: nowrap;
  }

  .nav-item {
    padding: 0 12px;
    font-size: 0.75rem;
  }

  .nav-links {
    gap: 2px;
  }
}

@media (min-width: 769px) and (max-width: 1280px) and (orientation: landscape) {
  .top-nav {
    height: 52px;
    padding: 0 16px;
  }

  .nav-logo img {
    width: 26px;
    height: 26px;
  }

  .nav-logo span {
    font-size: 0.75rem;
  }

  .current-tool-title {
    font-size: 0.7rem;
    padding: 5px 14px;
  }

  .nav-item {
    padding: 0 10px;
    font-size: 0.7rem;
    height: 52px;
  }

  .dropdown-content {
    max-height: 350px;
    overflow-y: auto;
  }
}

@media (min-width: 1281px) and (max-width: 1600px) and (orientation: landscape) and (min-resolution: 2dppx) {
  .top-nav {
    height: 58px;
  }

  .nav-item {
    height: 58px;
  }
}

@media (max-width: 768px) {
  .top-nav {
    padding: 0 12px;
    height: auto;
    min-height: 55px;
    grid-template-columns: 1fr auto !important;
    gap: 10px;
  }

  .nav-left {
    justify-content: flex-start;
  }

  .nav-logo img {
    width: 28px;
    height: 28px;
  }

  .nav-logo span {
    display: none;
  }

  .nav-center {
    display: none !important;
  }

  .nav-right {
    justify-content: flex-end;
  }

  .nav-links {
    gap: 0;
    height: auto;
  }

  .nav-item {
    padding: 0 8px;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    height: 55px;
  }

  .tool-dropdown:hover .dropdown-content {
    display: none;
  }

  button {
    padding: 12px;
    font-size: 0.9rem;
  }

  button,
  .nav-item,
  .card,
  .checkbox-container,
  .history-item {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(56, 189, 248, 0.2);
  }

  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .dropdown-content {
    position: fixed;
    top: auto;
    bottom: 20px;
    left: 20px;
    right: 20px;
    transform: none;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 16px;
    z-index: 2000;
  }

  .tool-dropdown:hover .dropdown-content {
    display: none;
  }

  .dropdown-content.active {
    display: block !important;
  }
}

@media (max-width: 480px) {
  .top-nav {
    padding: 0 8px;
  }

  .nav-item {
    padding: 0 6px;
    font-size: 0.65rem;
  }

  .nav-links {
    gap: 0;
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .top-nav {
    min-height: 48px;
    height: 48px;
  }

  .nav-item {
    height: 48px;
    padding: 0 6px;
    font-size: 0.6rem;
  }

  .nav-logo img {
    width: 24px;
    height: 24px;
  }
}

@media print {
  .top-nav,
  .btn-back,
  .db-selector-panel,
  button:not(#btnPrint) {
    display: none !important;
  }

  .main-container {
    display: block;
    padding: 0;
    margin: 0;
  }

  canvas {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}
